John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 1 | // |
| 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 Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 7 | #include "Diagnostics.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 8 | |
Nicolas Capens | cc863da | 2015-01-21 15:50:55 -0500 | [diff] [blame] | 9 | #include "debug.h" |
| 10 | #include "InfoSink.h" |
| 11 | #include "preprocessor/SourceLocation.h" |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 12 | |
| 13 | TDiagnostics::TDiagnostics(TInfoSink& infoSink) : |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame^] | 14 | mShaderVersion(100), |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 15 | mInfoSink(infoSink), |
| 16 | mNumErrors(0), |
| 17 | mNumWarnings(0) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | TDiagnostics::~TDiagnostics() |
| 22 | { |
| 23 | } |
| 24 | |
Nicolas Capens | b28964b | 2015-02-10 15:23:06 -0500 | [diff] [blame^] | 25 | void TDiagnostics::setShaderVersion(int version) |
| 26 | { |
| 27 | mShaderVersion = version; |
| 28 | } |
| 29 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 30 | void 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 | |
| 59 | void TDiagnostics::writeDebug(const std::string& str) |
| 60 | { |
| 61 | mInfoSink.debug << str; |
| 62 | } |
| 63 | |
| 64 | void TDiagnostics::print(ID id, |
| 65 | const pp::SourceLocation& loc, |
| 66 | const std::string& text) |
| 67 | { |
| 68 | writeInfo(severity(id), loc, message(id), text, ""); |
| 69 | } |