blob: 07b6b159687e4e56bde447cde134be2c7f69c8da [file] [log] [blame]
Douglas Gregord93256e2010-01-28 06:00:51 +00001/*===-- CIndexDiagnostic.h - Diagnostics C Interface ------------*- C++ -*-===*\
Douglas Gregor5352ac02010-01-28 00:27:43 +00002|* *|
3|* The LLVM Compiler Infrastructure *|
4|* *|
5|* This file is distributed under the University of Illinois Open Source *|
6|* License. See LICENSE.TXT for details. *|
7|* *|
8|*===----------------------------------------------------------------------===*|
9|* *|
10|* Implements the diagnostic functions of the Clang C interface. *|
11|* *|
12\*===----------------------------------------------------------------------===*/
13#ifndef LLVM_CLANG_CINDEX_DIAGNOSTIC_H
14#define LLVM_CLANG_CINDEX_DIAGNOSTIC_H
15
Ted Kremenek1edabbc2011-10-31 21:40:19 +000016#include "clang-c/Index.h"
17
Douglas Gregor5352ac02010-01-28 00:27:43 +000018namespace clang {
19
Daniel Dunbar35b84402010-01-30 23:31:40 +000020class LangOptions;
Benjamin Kramerb846deb2010-04-12 19:45:50 +000021class StoredDiagnostic;
Daniel Dunbar49146122010-01-30 23:31:49 +000022
Ted Kremenek1edabbc2011-10-31 21:40:19 +000023class CXDiagnosticImpl {
24public:
25 enum Kind { StoredDiagnosticKind, SerializedDiagnosticKind };
26
27 virtual ~CXDiagnosticImpl();
28
29 /// \brief Return the severity of the diagnostic.
30 virtual CXDiagnosticSeverity getSeverity() const = 0;
31
32 /// \brief Return the location of the diagnostic.
33 virtual CXSourceLocation getLocation() const = 0;
34
35 /// \brief Return the spelling of the diagnostic.
36 virtual CXString getSpelling() const = 0;
37
38 /// \brief Return the text for the diagnostic option.
39 virtual CXString getDiagnosticOption(CXString *Disable) const = 0;
40
41 /// \brief Return the category of the diagnostic.
42 virtual unsigned getCategory() const = 0;
43
44 /// \brief Return the number of source ranges for the diagnostic.
45 virtual unsigned getNumRanges() const = 0;
46
47 /// \brief Return the source ranges for the diagnostic.
48 virtual CXSourceRange getRange(unsigned Range) const = 0;
49
50 /// \brief Return the number of FixIts.
51 virtual unsigned getNumFixIts() const = 0;
52
53 /// \brief Return the FixIt information (source range and inserted text).
54 virtual CXString getFixIt(unsigned FixIt,
55 CXSourceRange *ReplacementRange) const = 0;
56
57 Kind getKind() const { return K; }
58
59protected:
60 CXDiagnosticImpl(Kind k) : K(k) {}
61
62private:
63 Kind K;
64};
65
Douglas Gregora88084b2010-02-18 18:08:43 +000066/// \brief The storage behind a CXDiagnostic
Ted Kremenek1edabbc2011-10-31 21:40:19 +000067struct CXStoredDiagnostic : public CXDiagnosticImpl {
Douglas Gregora88084b2010-02-18 18:08:43 +000068 const StoredDiagnostic &Diag;
69 const LangOptions &LangOpts;
70
71 CXStoredDiagnostic(const StoredDiagnostic &Diag,
72 const LangOptions &LangOpts)
Ted Kremenek1edabbc2011-10-31 21:40:19 +000073 : CXDiagnosticImpl(StoredDiagnosticKind),
74 Diag(Diag), LangOpts(LangOpts) { }
75
76 virtual ~CXStoredDiagnostic() {}
77
78 /// \brief Return the severity of the diagnostic.
79 virtual CXDiagnosticSeverity getSeverity() const;
80
81 /// \brief Return the location of the diagnostic.
82 virtual CXSourceLocation getLocation() const;
83
84 /// \brief Return the spelling of the diagnostic.
85 virtual CXString getSpelling() const;
86
87 /// \brief Return the text for the diagnostic option.
88 virtual CXString getDiagnosticOption(CXString *Disable) const;
89
90 /// \brief Return the category of the diagnostic.
91 virtual unsigned getCategory() const;
92
93 /// \brief Return the number of source ranges for the diagnostic.
94 virtual unsigned getNumRanges() const;
95
96 /// \brief Return the source ranges for the diagnostic.
97 virtual CXSourceRange getRange(unsigned Range) const;
98
99 /// \brief Return the number of FixIts.
100 virtual unsigned getNumFixIts() const;
101
102 /// \brief Return the FixIt information (source range and inserted text).
103 virtual CXString getFixIt(unsigned FixIt,
104 CXSourceRange *ReplacementRange) const;
105
106 static bool classof(const CXDiagnosticImpl *D) {
107 return D->getKind() == StoredDiagnosticKind;
108 }
Douglas Gregor5352ac02010-01-28 00:27:43 +0000109};
Douglas Gregord93256e2010-01-28 06:00:51 +0000110
Douglas Gregor5352ac02010-01-28 00:27:43 +0000111} // end namespace clang
112
113#endif // LLVM_CLANG_CINDEX_DIAGNOSTIC_H