Line data Source code
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 : #include "compiler/translator/Diagnostics.h"
8 :
9 : #include "common/debug.h"
10 : #include "compiler/preprocessor/SourceLocation.h"
11 : #include "compiler/translator/Common.h"
12 : #include "compiler/translator/InfoSink.h"
13 :
14 : namespace sh
15 : {
16 :
17 0 : TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
18 : mInfoSink(infoSink),
19 : mNumErrors(0),
20 0 : mNumWarnings(0)
21 : {
22 0 : }
23 :
24 0 : TDiagnostics::~TDiagnostics()
25 : {
26 0 : }
27 :
28 0 : void TDiagnostics::writeInfo(Severity severity,
29 : const pp::SourceLocation& loc,
30 : const std::string& reason,
31 : const std::string& token,
32 : const std::string& extra)
33 : {
34 0 : TPrefixType prefix = EPrefixNone;
35 0 : switch (severity)
36 : {
37 : case PP_ERROR:
38 0 : ++mNumErrors;
39 0 : prefix = EPrefixError;
40 0 : break;
41 : case PP_WARNING:
42 0 : ++mNumWarnings;
43 0 : prefix = EPrefixWarning;
44 0 : break;
45 : default:
46 0 : UNREACHABLE();
47 : break;
48 : }
49 :
50 0 : TInfoSinkBase& sink = mInfoSink.info;
51 : /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
52 0 : sink.prefix(prefix);
53 0 : sink.location(loc.file, loc.line);
54 0 : sink << "'" << token << "' : " << reason << " " << extra << "\n";
55 0 : }
56 :
57 0 : void TDiagnostics::error(const TSourceLoc &loc,
58 : const char *reason,
59 : const char *token,
60 : const char *extraInfo)
61 : {
62 0 : pp::SourceLocation srcLoc;
63 0 : srcLoc.file = loc.first_file;
64 0 : srcLoc.line = loc.first_line;
65 0 : writeInfo(pp::Diagnostics::PP_ERROR, srcLoc, reason, token, extraInfo);
66 0 : }
67 :
68 0 : void TDiagnostics::warning(const TSourceLoc &loc,
69 : const char *reason,
70 : const char *token,
71 : const char *extraInfo)
72 : {
73 0 : pp::SourceLocation srcLoc;
74 0 : srcLoc.file = loc.first_file;
75 0 : srcLoc.line = loc.first_line;
76 0 : writeInfo(pp::Diagnostics::PP_WARNING, srcLoc, reason, token, extraInfo);
77 0 : }
78 :
79 0 : void TDiagnostics::print(ID id,
80 : const pp::SourceLocation& loc,
81 : const std::string& text)
82 : {
83 0 : writeInfo(severity(id), loc, message(id), text, "");
84 0 : }
85 :
86 : } // namespace sh
|