Diagnostics.cpp (2801B)
1 // 2 // Copyright 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 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 TDiagnostics::TDiagnostics(TInfoSinkBase &infoSink) 18 : mInfoSink(infoSink), mNumErrors(0), mNumWarnings(0) 19 {} 20 21 TDiagnostics::~TDiagnostics() {} 22 23 void TDiagnostics::writeInfo(Severity severity, 24 const angle::pp::SourceLocation &loc, 25 const char *reason, 26 const char *token) 27 { 28 switch (severity) 29 { 30 case SH_ERROR: 31 ++mNumErrors; 32 break; 33 case SH_WARNING: 34 ++mNumWarnings; 35 break; 36 default: 37 UNREACHABLE(); 38 break; 39 } 40 41 /* VC++ format: file(linenum) : error #: 'token' : extrainfo */ 42 mInfoSink.prefix(severity); 43 mInfoSink.location(loc.file, loc.line); 44 mInfoSink << "'" << token << "' : " << reason << "\n"; 45 } 46 47 void TDiagnostics::globalError(const char *message) 48 { 49 ++mNumErrors; 50 mInfoSink.prefix(SH_ERROR); 51 mInfoSink << message << "\n"; 52 } 53 54 void TDiagnostics::error(const angle::pp::SourceLocation &loc, 55 const char *reason, 56 const char *token) 57 { 58 writeInfo(SH_ERROR, loc, reason, token); 59 } 60 61 void TDiagnostics::warning(const angle::pp::SourceLocation &loc, 62 const char *reason, 63 const char *token) 64 { 65 writeInfo(SH_WARNING, loc, reason, token); 66 } 67 68 void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *token) 69 { 70 angle::pp::SourceLocation srcLoc; 71 srcLoc.file = loc.first_file; 72 srcLoc.line = loc.first_line; 73 error(srcLoc, reason, token); 74 } 75 76 void TDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token) 77 { 78 angle::pp::SourceLocation srcLoc; 79 srcLoc.file = loc.first_file; 80 srcLoc.line = loc.first_line; 81 warning(srcLoc, reason, token); 82 } 83 84 void TDiagnostics::print(ID id, const angle::pp::SourceLocation &loc, const std::string &text) 85 { 86 writeInfo(isError(id) ? SH_ERROR : SH_WARNING, loc, message(id), text.c_str()); 87 } 88 89 void TDiagnostics::resetErrorCount() 90 { 91 mNumErrors = 0; 92 mNumWarnings = 0; 93 } 94 95 PerformanceDiagnostics::PerformanceDiagnostics(TDiagnostics *diagnostics) 96 : mDiagnostics(diagnostics) 97 { 98 ASSERT(diagnostics); 99 } 100 101 void PerformanceDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token) 102 { 103 mDiagnostics->warning(loc, reason, token); 104 } 105 106 } // namespace sh