| 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" |
| 13 | #include "clang/AST/ASTContext.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 | |
| 19 | namespace clang { |
| 20 | |
| 21 | template <typename NamedDeclDerivedT> |
| 22 | void 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 | |
| 30 | template <typename NamedDeclDerivedT> |
| 31 | void printQuotedName(llvm::raw_ostream &Os, const NamedDeclDerivedT &D) { |
| 32 | Os << "'" ; |
| 33 | D->getNameForDiagnostic(Os, D->getASTContext().getPrintingPolicy(), |
| 34 | /*Qualified=*/false); |
| 35 | Os << "'" ; |
| 36 | } |
| 37 | |
| 38 | inline 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, D: CXXRD); |
| 43 | return; |
| 44 | } |
| 45 | if (auto *ObjCDecl = getObjCDeclFromObjCPtr(TypePtr: Type)) { |
| 46 | printQuotedQualifiedName(Os, D: ObjCDecl); |
| 47 | return; |
| 48 | } |
| 49 | if (!Type->isPointerOrReferenceType()) { |
| 50 | if (auto *RD = Type->getAsRecordDecl()) |
| 51 | printQuotedQualifiedName(Os, D: RD); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | } // namespace clang |
| 56 | |
| 57 | #endif |
| 58 | |