Unify Diagnostics interface

Use the same kind of interface for reporting preprocessor errors as
for reporting regular compiler errors, and make global errors like
having too many uniforms also go through Diagnostics. Also don't
create std::string objects unnecessarily.

Includes cleanups of some dead code related to reporting errors.

BUG=angleproject:1670
TEST=angle_unittests

Change-Id: I3ee794d32ddeec1826bdf1b76b558f35259f82c0
Reviewed-on: https://chromium-review.googlesource.com/421527
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Diagnostics.cpp b/src/compiler/translator/Diagnostics.cpp
index 256c938..d2fe429 100644
--- a/src/compiler/translator/Diagnostics.cpp
+++ b/src/compiler/translator/Diagnostics.cpp
@@ -14,7 +14,7 @@
 namespace sh
 {
 
-TDiagnostics::TDiagnostics(TInfoSink &infoSink)
+TDiagnostics::TDiagnostics(TInfoSinkBase &infoSink)
     : mInfoSink(infoSink), mNumErrors(0), mNumWarnings(0)
 {
 }
@@ -25,30 +25,43 @@
 
 void TDiagnostics::writeInfo(Severity severity,
                              const pp::SourceLocation &loc,
-                             const std::string &reason,
-                             const std::string &token)
+                             const char *reason,
+                             const char *token)
 {
-    TPrefixType prefix = EPrefixNone;
     switch (severity)
     {
-        case PP_ERROR:
+        case SH_ERROR:
             ++mNumErrors;
-            prefix = EPrefixError;
             break;
-        case PP_WARNING:
+        case SH_WARNING:
             ++mNumWarnings;
-            prefix = EPrefixWarning;
             break;
         default:
             UNREACHABLE();
             break;
     }
 
-    TInfoSinkBase &sink = mInfoSink.info;
     /* VC++ format: file(linenum) : error #: 'token' : extrainfo */
-    sink.prefix(prefix);
-    sink.location(loc.file, loc.line);
-    sink << "'" << token << "' : " << reason << "\n";
+    mInfoSink.prefix(severity);
+    mInfoSink.location(loc.file, loc.line);
+    mInfoSink << "'" << token << "' : " << reason << "\n";
+}
+
+void TDiagnostics::globalError(const char *message)
+{
+    ++mNumErrors;
+    mInfoSink.prefix(SH_ERROR);
+    mInfoSink << message << "\n";
+}
+
+void TDiagnostics::error(const pp::SourceLocation &loc, const char *reason, const char *token)
+{
+    writeInfo(SH_ERROR, loc, reason, token);
+}
+
+void TDiagnostics::warning(const pp::SourceLocation &loc, const char *reason, const char *token)
+{
+    writeInfo(SH_WARNING, loc, reason, token);
 }
 
 void TDiagnostics::error(const TSourceLoc &loc, const char *reason, const char *token)
@@ -56,7 +69,7 @@
     pp::SourceLocation srcLoc;
     srcLoc.file = loc.first_file;
     srcLoc.line = loc.first_line;
-    writeInfo(pp::Diagnostics::PP_ERROR, srcLoc, reason, token);
+    error(srcLoc, reason, token);
 }
 
 void TDiagnostics::warning(const TSourceLoc &loc, const char *reason, const char *token)
@@ -64,12 +77,18 @@
     pp::SourceLocation srcLoc;
     srcLoc.file = loc.first_file;
     srcLoc.line = loc.first_line;
-    writeInfo(pp::Diagnostics::PP_WARNING, srcLoc, reason, token);
+    warning(srcLoc, reason, token);
 }
 
 void TDiagnostics::print(ID id, const pp::SourceLocation &loc, const std::string &text)
 {
-    writeInfo(severity(id), loc, message(id), text);
+    writeInfo(isError(id) ? SH_ERROR : SH_WARNING, loc, message(id), text.c_str());
+}
+
+void TDiagnostics::resetErrorCount()
+{
+    mNumErrors   = 0;
+    mNumWarnings = 0;
 }
 
 }  // namespace sh