blob: 71a3d1249700edba455c6f86564013254e10710d [file] [log] [blame]
alokp@chromium.org8b851c62012-06-15 16:25:11 +00001//
shannon.woods%transgaming.com@gtempaccount.com0bbed382013-04-13 03:38:07 +00002// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
alokp@chromium.org8b851c62012-06-15 16:25:11 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang17732822013-08-29 13:46:49 -04007#include "compiler/translator/Diagnostics.h"
alokp@chromium.org8b851c62012-06-15 16:25:11 +00008
Geoff Lang17732822013-08-29 13:46:49 -04009#include "compiler/translator/compilerdebug.h"
10#include "compiler/translator/InfoSink.h"
daniel@transgaming.comb401a922012-10-26 18:58:24 +000011#include "compiler/preprocessor/SourceLocation.h"
alokp@chromium.org8b851c62012-06-15 16:25:11 +000012
alokp@chromium.org6b495712012-06-29 00:06:58 +000013TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
14 mInfoSink(infoSink),
15 mNumErrors(0),
16 mNumWarnings(0)
alokp@chromium.org8b851c62012-06-15 16:25:11 +000017{
18}
19
20TDiagnostics::~TDiagnostics()
21{
22}
23
24void TDiagnostics::writeInfo(Severity severity,
25 const pp::SourceLocation& loc,
26 const std::string& reason,
27 const std::string& token,
28 const std::string& extra)
29{
alokp@chromium.org6b495712012-06-29 00:06:58 +000030 TPrefixType prefix = EPrefixNone;
31 switch (severity)
32 {
33 case ERROR:
34 ++mNumErrors;
35 prefix = EPrefixError;
36 break;
37 case WARNING:
38 ++mNumWarnings;
39 prefix = EPrefixWarning;
40 break;
41 default:
42 UNREACHABLE();
43 break;
44 }
alokp@chromium.org8b851c62012-06-15 16:25:11 +000045
alokp@chromium.org6b495712012-06-29 00:06:58 +000046 TInfoSinkBase& sink = mInfoSink.info;
alokp@chromium.org8b851c62012-06-15 16:25:11 +000047 /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
48 sink.prefix(prefix);
Jamie Madill075edd82013-07-08 13:30:19 -040049 sink.location(loc.file, loc.line);
alokp@chromium.org8b851c62012-06-15 16:25:11 +000050 sink << "'" << token << "' : " << reason << " " << extra << "\n";
51}
52
53void TDiagnostics::writeDebug(const std::string& str)
54{
55 mInfoSink.debug << str;
56}
57
58void TDiagnostics::print(ID id,
59 const pp::SourceLocation& loc,
60 const std::string& text)
61{
alokp@chromium.org6b495712012-06-29 00:06:58 +000062 writeInfo(severity(id), loc, message(id), text, "");
alokp@chromium.org8b851c62012-06-15 16:25:11 +000063}