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_TEXTDIAGNOSTIC_H
0016 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
0017
0018 #include "clang/Frontend/DiagnosticRenderer.h"
0019 #include "llvm/Support/raw_ostream.h"
0020
0021 namespace clang {
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 class TextDiagnostic : public DiagnosticRenderer {
0036 raw_ostream &OS;
0037 const Preprocessor *PP;
0038
0039 public:
0040 TextDiagnostic(raw_ostream &OS, const LangOptions &LangOpts,
0041 DiagnosticOptions *DiagOpts, const Preprocessor *PP = nullptr);
0042
0043 ~TextDiagnostic() override;
0044
0045 struct StyleRange {
0046 unsigned Start;
0047 unsigned End;
0048 enum llvm::raw_ostream::Colors Color;
0049 StyleRange(unsigned S, unsigned E, enum llvm::raw_ostream::Colors C)
0050 : Start(S), End(E), Color(C){};
0051 };
0052
0053
0054
0055
0056
0057
0058
0059
0060 static void printDiagnosticLevel(raw_ostream &OS,
0061 DiagnosticsEngine::Level Level,
0062 bool ShowColors);
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080 static void printDiagnosticMessage(raw_ostream &OS, bool IsSupplemental,
0081 StringRef Message, unsigned CurrentColumn,
0082 unsigned Columns, bool ShowColors);
0083
0084 protected:
0085 void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
0086 DiagnosticsEngine::Level Level, StringRef Message,
0087 ArrayRef<CharSourceRange> Ranges,
0088 DiagOrStoredDiag D) override;
0089
0090 void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
0091 DiagnosticsEngine::Level Level,
0092 ArrayRef<CharSourceRange> Ranges) override;
0093
0094 void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0095 SmallVectorImpl<CharSourceRange> &Ranges,
0096 ArrayRef<FixItHint> Hints) override {
0097 emitSnippetAndCaret(Loc, Level, Ranges, Hints);
0098 }
0099
0100 void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override;
0101
0102 void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0103 StringRef ModuleName) override;
0104
0105 void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
0106 StringRef ModuleName) override;
0107
0108 private:
0109 void emitFilename(StringRef Filename, const SourceManager &SM);
0110
0111 void emitSnippetAndCaret(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
0112 SmallVectorImpl<CharSourceRange> &Ranges,
0113 ArrayRef<FixItHint> Hints);
0114
0115 void emitSnippet(StringRef SourceLine, unsigned MaxLineNoDisplayWidth,
0116 unsigned LineNo, unsigned DisplayLineNo,
0117 ArrayRef<StyleRange> Styles);
0118
0119 void emitParseableFixits(ArrayRef<FixItHint> Hints, const SourceManager &SM);
0120 };
0121
0122 }
0123
0124 #endif