File indexing completed on 2026-05-10 08:36:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H
0016 #define LLVM_CLANG_FRONTEND_DIAGNOSTICRENDERER_H
0017
0018 #include "clang/Basic/Diagnostic.h"
0019 #include "clang/Basic/DiagnosticOptions.h"
0020 #include "clang/Basic/LLVM.h"
0021 #include "clang/Basic/SourceLocation.h"
0022 #include "llvm/ADT/ArrayRef.h"
0023 #include "llvm/ADT/IntrusiveRefCntPtr.h"
0024 #include "llvm/ADT/PointerUnion.h"
0025 #include "llvm/ADT/StringRef.h"
0026
0027 namespace clang {
0028
0029 class LangOptions;
0030 class SourceManager;
0031
0032 using DiagOrStoredDiag =
0033 llvm::PointerUnion<const Diagnostic *, const StoredDiagnostic *>;
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047 class DiagnosticRenderer {
0048 protected:
0049 const LangOptions &LangOpts;
0050 IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
0051
0052
0053
0054
0055
0056
0057 SourceLocation LastLoc;
0058
0059
0060
0061
0062
0063 SourceLocation LastIncludeLoc;
0064
0065
0066
0067
0068
0069 DiagnosticsEngine::Level LastLevel = DiagnosticsEngine::Ignored;
0070
0071 DiagnosticRenderer(const LangOptions &LangOpts,
0072 DiagnosticOptions *DiagOpts);
0073
0074 virtual ~DiagnosticRenderer();
0075
0076 virtual void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
0077 DiagnosticsEngine::Level Level,
0078 StringRef Message,
0079 ArrayRef<CharSourceRange> Ranges,
0080 DiagOrStoredDiag Info) = 0;
0081
0082 virtual void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
0083 DiagnosticsEngine::Level Level,
0084 ArrayRef<CharSourceRange> Ranges) = 0;
0085
0086 virtual void emitCodeContext(FullSourceLoc Loc,
0087 DiagnosticsEngine::Level Level,
0088 SmallVectorImpl<CharSourceRange> &Ranges,
0089 ArrayRef<FixItHint> Hints) = 0;
0090
0091 virtual void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) = 0;
0092 virtual void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0093 StringRef ModuleName) = 0;
0094 virtual void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0095 StringRef ModuleName) = 0;
0096
0097 virtual void beginDiagnostic(DiagOrStoredDiag D,
0098 DiagnosticsEngine::Level Level) {}
0099 virtual void endDiagnostic(DiagOrStoredDiag D,
0100 DiagnosticsEngine::Level Level) {}
0101
0102 private:
0103 void emitBasicNote(StringRef Message);
0104 void emitIncludeStack(FullSourceLoc Loc, PresumedLoc PLoc,
0105 DiagnosticsEngine::Level Level);
0106 void emitIncludeStackRecursively(FullSourceLoc Loc);
0107 void emitImportStack(FullSourceLoc Loc);
0108 void emitImportStackRecursively(FullSourceLoc Loc, StringRef ModuleName);
0109 void emitModuleBuildStack(const SourceManager &SM);
0110 void emitCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0111 ArrayRef<CharSourceRange> Ranges, ArrayRef<FixItHint> Hints);
0112 void emitSingleMacroExpansion(FullSourceLoc Loc,
0113 DiagnosticsEngine::Level Level,
0114 ArrayRef<CharSourceRange> Ranges);
0115 void emitMacroExpansions(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0116 ArrayRef<CharSourceRange> Ranges,
0117 ArrayRef<FixItHint> Hints);
0118
0119 public:
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 void emitDiagnostic(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0133 StringRef Message, ArrayRef<CharSourceRange> Ranges,
0134 ArrayRef<FixItHint> FixItHints,
0135 DiagOrStoredDiag D = (Diagnostic *)nullptr);
0136
0137 void emitStoredDiagnostic(StoredDiagnostic &Diag);
0138 };
0139
0140
0141
0142 class DiagnosticNoteRenderer : public DiagnosticRenderer {
0143 public:
0144 DiagnosticNoteRenderer(const LangOptions &LangOpts,
0145 DiagnosticOptions *DiagOpts)
0146 : DiagnosticRenderer(LangOpts, DiagOpts) {}
0147
0148 ~DiagnosticNoteRenderer() override;
0149
0150 void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
0151
0152 void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0153 StringRef ModuleName) override;
0154
0155 void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0156 StringRef ModuleName) override;
0157
0158 virtual void emitNote(FullSourceLoc Loc, StringRef Message) = 0;
0159 };
0160
0161 }
0162
0163 #endif