blob: 8037af03e27f7d8e0d1a31983af259ec00bd523a [file] [log] [blame]
John Bauman66b8ab22014-05-06 15:57:45 -04001//
2// Copyright (c) 2012 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
Nicolas Capenscc863da2015-01-21 15:50:55 -05007#include "Diagnostics.h"
John Bauman66b8ab22014-05-06 15:57:45 -04008
Nicolas Capenscc863da2015-01-21 15:50:55 -05009#include "debug.h"
10#include "InfoSink.h"
11#include "preprocessor/SourceLocation.h"
John Bauman66b8ab22014-05-06 15:57:45 -040012
13TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
Nicolas Capensb28964b2015-02-10 15:23:06 -050014 mShaderVersion(100),
John Bauman66b8ab22014-05-06 15:57:45 -040015 mInfoSink(infoSink),
16 mNumErrors(0),
17 mNumWarnings(0)
18{
19}
20
21TDiagnostics::~TDiagnostics()
22{
23}
24
Nicolas Capensb28964b2015-02-10 15:23:06 -050025void TDiagnostics::setShaderVersion(int version)
26{
27 mShaderVersion = version;
28}
29
John Bauman66b8ab22014-05-06 15:57:45 -040030void TDiagnostics::writeInfo(Severity severity,
31 const pp::SourceLocation& loc,
32 const std::string& reason,
33 const std::string& token,
34 const std::string& extra)
35{
36 TPrefixType prefix = EPrefixNone;
37 switch (severity)
38 {
39 case PP_ERROR:
40 ++mNumErrors;
41 prefix = EPrefixError;
42 break;
43 case PP_WARNING:
44 ++mNumWarnings;
45 prefix = EPrefixWarning;
46 break;
47 default:
48 UNREACHABLE();
49 break;
50 }
51
52 TInfoSinkBase& sink = mInfoSink.info;
53 /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
54 sink.prefix(prefix);
55 sink.location(EncodeSourceLoc(loc.file, loc.line));
56 sink << "'" << token << "' : " << reason << " " << extra << "\n";
57}
58
59void TDiagnostics::writeDebug(const std::string& str)
60{
61 mInfoSink.debug << str;
62}
63
64void TDiagnostics::print(ID id,
65 const pp::SourceLocation& loc,
66 const std::string& text)
67{
68 writeInfo(severity(id), loc, message(id), text, "");
69}