michael@0: // michael@0: // Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: // michael@0: michael@0: #include "compiler/Diagnostics.h" michael@0: michael@0: #include "compiler/compiler_debug.h" michael@0: #include "compiler/InfoSink.h" michael@0: #include "compiler/preprocessor/SourceLocation.h" michael@0: michael@0: TDiagnostics::TDiagnostics(TInfoSink& infoSink) : michael@0: mInfoSink(infoSink), michael@0: mNumErrors(0), michael@0: mNumWarnings(0) michael@0: { michael@0: } michael@0: michael@0: TDiagnostics::~TDiagnostics() michael@0: { michael@0: } michael@0: michael@0: void TDiagnostics::writeInfo(Severity severity, michael@0: const pp::SourceLocation& loc, michael@0: const std::string& reason, michael@0: const std::string& token, michael@0: const std::string& extra) michael@0: { michael@0: TPrefixType prefix = EPrefixNone; michael@0: switch (severity) michael@0: { michael@0: case ERROR: michael@0: ++mNumErrors; michael@0: prefix = EPrefixError; michael@0: break; michael@0: case WARNING: michael@0: ++mNumWarnings; michael@0: prefix = EPrefixWarning; michael@0: break; michael@0: default: michael@0: UNREACHABLE(); michael@0: break; michael@0: } michael@0: michael@0: TInfoSinkBase& sink = mInfoSink.info; michael@0: /* VC++ format: file(linenum) : error #: 'token' : extrainfo */ michael@0: sink.prefix(prefix); michael@0: sink.location(loc.file, loc.line); michael@0: sink << "'" << token << "' : " << reason << " " << extra << "\n"; michael@0: } michael@0: michael@0: void TDiagnostics::writeDebug(const std::string& str) michael@0: { michael@0: mInfoSink.debug << str; michael@0: } michael@0: michael@0: void TDiagnostics::print(ID id, michael@0: const pp::SourceLocation& loc, michael@0: const std::string& text) michael@0: { michael@0: writeInfo(severity(id), loc, message(id), text, ""); michael@0: }