File indexing completed on 2026-05-10 08:36:40
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CLANG_AST_OPTIONALDIAGNOSTIC_H
0015 #define LLVM_CLANG_AST_OPTIONALDIAGNOSTIC_H
0016
0017 #include "clang/AST/APValue.h"
0018 #include "clang/Basic/PartialDiagnostic.h"
0019 #include "llvm/ADT/APFloat.h"
0020 #include "llvm/ADT/APSInt.h"
0021 #include "llvm/ADT/SmallVector.h"
0022 #include "llvm/ADT/StringRef.h"
0023
0024 namespace clang {
0025
0026
0027
0028 class OptionalDiagnostic {
0029 PartialDiagnostic *Diag;
0030
0031 public:
0032 explicit OptionalDiagnostic(PartialDiagnostic *Diag = nullptr) : Diag(Diag) {}
0033
0034 template <typename T> OptionalDiagnostic &operator<<(const T &v) {
0035 if (Diag)
0036 *Diag << v;
0037 return *this;
0038 }
0039
0040 OptionalDiagnostic &operator<<(const llvm::APSInt &I) {
0041 if (Diag) {
0042 SmallVector<char, 32> Buffer;
0043 I.toString(Buffer);
0044 *Diag << StringRef(Buffer.data(), Buffer.size());
0045 }
0046 return *this;
0047 }
0048
0049 OptionalDiagnostic &operator<<(const llvm::APFloat &F) {
0050 if (Diag) {
0051
0052
0053
0054
0055
0056
0057 unsigned precision = llvm::APFloat::semanticsPrecision(F.getSemantics());
0058 precision = (precision * 59 + 195) / 196;
0059 SmallVector<char, 32> Buffer;
0060 F.toString(Buffer, precision);
0061 *Diag << StringRef(Buffer.data(), Buffer.size());
0062 }
0063 return *this;
0064 }
0065
0066 OptionalDiagnostic &operator<<(const llvm::APFixedPoint &FX) {
0067 if (Diag) {
0068 SmallVector<char, 32> Buffer;
0069 FX.toString(Buffer);
0070 *Diag << StringRef(Buffer.data(), Buffer.size());
0071 }
0072 return *this;
0073 }
0074 };
0075
0076 }
0077
0078 #endif