1*e5dd7070Spatrick /*===-- CXLoadedDiagnostic.h - Handling of persisent diags ------*- C++ -*-===*\
2*e5dd7070Spatrick |*                                                                            *|
3*e5dd7070Spatrick |* Part of the LLVM Project, under the Apache License v2.0 with LLVM          *|
4*e5dd7070Spatrick |* Exceptions.                                                                *|
5*e5dd7070Spatrick |* See https://llvm.org/LICENSE.txt for license information.                  *|
6*e5dd7070Spatrick |* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception                    *|
7*e5dd7070Spatrick |*                                                                            *|
8*e5dd7070Spatrick |*===----------------------------------------------------------------------===*|
9*e5dd7070Spatrick |*                                                                            *|
10*e5dd7070Spatrick |* Implements handling of persisent diagnostics.                              *|
11*e5dd7070Spatrick |*                                                                            *|
12*e5dd7070Spatrick \*===----------------------------------------------------------------------===*/
13*e5dd7070Spatrick 
14*e5dd7070Spatrick #ifndef LLVM_CLANG_TOOLS_LIBCLANG_CXLOADEDDIAGNOSTIC_H
15*e5dd7070Spatrick #define LLVM_CLANG_TOOLS_LIBCLANG_CXLOADEDDIAGNOSTIC_H
16*e5dd7070Spatrick 
17*e5dd7070Spatrick #include "CIndexDiagnostic.h"
18*e5dd7070Spatrick #include "llvm/ADT/StringRef.h"
19*e5dd7070Spatrick #include "clang/Basic/LLVM.h"
20*e5dd7070Spatrick #include <vector>
21*e5dd7070Spatrick 
22*e5dd7070Spatrick namespace clang {
23*e5dd7070Spatrick class CXLoadedDiagnostic : public CXDiagnosticImpl {
24*e5dd7070Spatrick public:
CXLoadedDiagnostic()25*e5dd7070Spatrick   CXLoadedDiagnostic() : CXDiagnosticImpl(LoadedDiagnosticKind),
26*e5dd7070Spatrick     severity(0), category(0) {}
27*e5dd7070Spatrick 
28*e5dd7070Spatrick   ~CXLoadedDiagnostic() override;
29*e5dd7070Spatrick 
30*e5dd7070Spatrick   /// Return the severity of the diagnostic.
31*e5dd7070Spatrick   CXDiagnosticSeverity getSeverity() const override;
32*e5dd7070Spatrick 
33*e5dd7070Spatrick   /// Return the location of the diagnostic.
34*e5dd7070Spatrick   CXSourceLocation getLocation() const override;
35*e5dd7070Spatrick 
36*e5dd7070Spatrick   /// Return the spelling of the diagnostic.
37*e5dd7070Spatrick   CXString getSpelling() const override;
38*e5dd7070Spatrick 
39*e5dd7070Spatrick   /// Return the text for the diagnostic option.
40*e5dd7070Spatrick   CXString getDiagnosticOption(CXString *Disable) const override;
41*e5dd7070Spatrick 
42*e5dd7070Spatrick   /// Return the category of the diagnostic.
43*e5dd7070Spatrick   unsigned getCategory() const override;
44*e5dd7070Spatrick 
45*e5dd7070Spatrick   /// Return the category string of the diagnostic.
46*e5dd7070Spatrick   CXString getCategoryText() const override;
47*e5dd7070Spatrick 
48*e5dd7070Spatrick   /// Return the number of source ranges for the diagnostic.
49*e5dd7070Spatrick   unsigned getNumRanges() const override;
50*e5dd7070Spatrick 
51*e5dd7070Spatrick   /// Return the source ranges for the diagnostic.
52*e5dd7070Spatrick   CXSourceRange getRange(unsigned Range) const override;
53*e5dd7070Spatrick 
54*e5dd7070Spatrick   /// Return the number of FixIts.
55*e5dd7070Spatrick   unsigned getNumFixIts() const override;
56*e5dd7070Spatrick 
57*e5dd7070Spatrick   /// Return the FixIt information (source range and inserted text).
58*e5dd7070Spatrick   CXString getFixIt(unsigned FixIt,
59*e5dd7070Spatrick                     CXSourceRange *ReplacementRange) const override;
60*e5dd7070Spatrick 
classof(const CXDiagnosticImpl * D)61*e5dd7070Spatrick   static bool classof(const CXDiagnosticImpl *D) {
62*e5dd7070Spatrick     return D->getKind() == LoadedDiagnosticKind;
63*e5dd7070Spatrick   }
64*e5dd7070Spatrick 
65*e5dd7070Spatrick   /// Decode the CXSourceLocation into file, line, column, and offset.
66*e5dd7070Spatrick   static void decodeLocation(CXSourceLocation location,
67*e5dd7070Spatrick                              CXFile *file,
68*e5dd7070Spatrick                              unsigned *line,
69*e5dd7070Spatrick                              unsigned *column,
70*e5dd7070Spatrick                              unsigned *offset);
71*e5dd7070Spatrick 
72*e5dd7070Spatrick   struct Location {
73*e5dd7070Spatrick     CXFile file;
74*e5dd7070Spatrick     unsigned line;
75*e5dd7070Spatrick     unsigned column;
76*e5dd7070Spatrick     unsigned offset;
77*e5dd7070Spatrick 
LocationLocation78*e5dd7070Spatrick     Location() : line(0), column(0), offset(0) {}
79*e5dd7070Spatrick   };
80*e5dd7070Spatrick 
81*e5dd7070Spatrick   Location DiagLoc;
82*e5dd7070Spatrick 
83*e5dd7070Spatrick   std::vector<CXSourceRange> Ranges;
84*e5dd7070Spatrick   std::vector<std::pair<CXSourceRange, const char *> > FixIts;
85*e5dd7070Spatrick   const char *Spelling;
86*e5dd7070Spatrick   llvm::StringRef DiagOption;
87*e5dd7070Spatrick   llvm::StringRef CategoryText;
88*e5dd7070Spatrick   unsigned severity;
89*e5dd7070Spatrick   unsigned category;
90*e5dd7070Spatrick };
91*e5dd7070Spatrick }
92*e5dd7070Spatrick 
93*e5dd7070Spatrick #endif
94