1 //
2 // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_DIAGNOSTICS_H_
8 #define COMPILER_TRANSLATOR_DIAGNOSTICS_H_
9 
10 #include "common/angleutils.h"
11 #include "compiler/preprocessor/DiagnosticsBase.h"
12 #include "compiler/translator/Severity.h"
13 
14 namespace sh
15 {
16 
17 class TInfoSinkBase;
18 struct TSourceLoc;
19 
20 class TDiagnostics : public pp::Diagnostics, angle::NonCopyable
21 {
22   public:
23     TDiagnostics(TInfoSinkBase &infoSink);
24     ~TDiagnostics() override;
25 
numErrors()26     int numErrors() const { return mNumErrors; }
numWarnings()27     int numWarnings() const { return mNumWarnings; }
28 
29     void error(const pp::SourceLocation &loc, const char *reason, const char *token);
30     void warning(const pp::SourceLocation &loc, const char *reason, const char *token);
31 
32     void error(const TSourceLoc &loc, const char *reason, const char *token);
33     void warning(const TSourceLoc &loc, const char *reason, const char *token);
34 
35     void globalError(const char *message);
36 
37     void resetErrorCount();
38 
39   protected:
40     void writeInfo(Severity severity,
41                    const pp::SourceLocation &loc,
42                    const char *reason,
43                    const char *token);
44 
45     void print(ID id, const pp::SourceLocation &loc, const std::string &text) override;
46 
47   private:
48     TInfoSinkBase &mInfoSink;
49     int mNumErrors;
50     int mNumWarnings;
51 };
52 
53 // Diagnostics wrapper to use when the code is only allowed to generate warnings.
54 class PerformanceDiagnostics : public angle::NonCopyable
55 {
56   public:
57     PerformanceDiagnostics(TDiagnostics *diagnostics);
58 
59     void warning(const TSourceLoc &loc, const char *reason, const char *token);
60 
61   private:
62     TDiagnostics *mDiagnostics;
63 };
64 
65 }  // namespace sh
66 
67 #endif  // COMPILER_TRANSLATOR_DIAGNOSTICS_H_
68