clang 24.0.0git
DiagOutputUtils.h
Go to the documentation of this file.
1//=======- DiagOutputUtils.h -------------------------------------*- 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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_CLANG_ANALYZER_WEBKIT_DIAGPRINTUTILS_H
10#define LLVM_CLANG_ANALYZER_WEBKIT_DIAGPRINTUTILS_H
11
12#include "ASTUtils.h"
14#include "clang/AST/Decl.h"
15#include "clang/AST/DeclCXX.h"
16#include "clang/AST/DeclObjC.h"
17#include "llvm/Support/raw_ostream.h"
18
19namespace clang {
20
21template <typename NamedDeclDerivedT>
22void printQuotedQualifiedName(llvm::raw_ostream &Os,
23 const NamedDeclDerivedT &D) {
24 Os << "'";
25 D->getNameForDiagnostic(Os, D->getASTContext().getPrintingPolicy(),
26 /*Qualified=*/true);
27 Os << "'";
28}
29
30template <typename NamedDeclDerivedT>
31void printQuotedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D) {
32 Os << "'";
33 D->getNameForDiagnostic(Os, D->getASTContext().getPrintingPolicy(),
34 /*Qualified=*/false);
35 Os << "'";
36}
37
38inline void printTypeName(llvm::raw_ostream &Os, const QualType QT) {
39 auto *Type = QT.getTypePtr();
40 assert(Type);
41 if (auto *CXXRD = Type->getPointeeCXXRecordDecl()) {
42 printQuotedQualifiedName(Os, CXXRD);
43 return;
44 }
45 if (auto *ObjCDecl = getObjCDeclFromObjCPtr(Type)) {
46 printQuotedQualifiedName(Os, ObjCDecl);
47 return;
48 }
50 if (auto *RD = Type->getAsRecordDecl())
52 }
53}
54
55} // namespace clang
56
57#endif
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
A (possibly-)qualified type.
Definition TypeBase.h:937
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition TypeBase.h:8447
The base class of the type hierarchy.
Definition TypeBase.h:1875
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Definition Type.h:41
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
Definition Type.cpp:1958
bool isPointerOrReferenceType() const
Definition TypeBase.h:8688
The JSON file list parser is used to communicate input to InstallAPI.
void printQuotedQualifiedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
void printQuotedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D)
void printTypeName(llvm::raw_ostream &Os, const QualType QT)
ObjCInterfaceDecl * getObjCDeclFromObjCPtr(const Type *TypePtr)
Definition ASTUtils.cpp:391