Commit 1cc598f8 by Olli Etuaho Committed by Commit Bot

Add error and warning helpers to Diagnostics

This will make it easier to generate errors and warnings with a consistent format outside of ParseContext, for example in TIntermBinary::fold() which warns about division by zero. BUG=angleproject:952 TEST=angle_unittests Change-Id: I25999d7bdc77efafe77785a0d6f4d63417dfaab9 Reviewed-on: https://chromium-review.googlesource.com/372719Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 244be01a
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
#include "compiler/translator/Diagnostics.h" #include "compiler/translator/Diagnostics.h"
#include "common/debug.h" #include "common/debug.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/preprocessor/SourceLocation.h" #include "compiler/preprocessor/SourceLocation.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/InfoSink.h"
TDiagnostics::TDiagnostics(TInfoSink& infoSink) : TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
mInfoSink(infoSink), mInfoSink(infoSink),
...@@ -50,6 +51,28 @@ void TDiagnostics::writeInfo(Severity severity, ...@@ -50,6 +51,28 @@ void TDiagnostics::writeInfo(Severity severity,
sink << "'" << token << "' : " << reason << " " << extra << "\n"; sink << "'" << token << "' : " << reason << " " << extra << "\n";
} }
void TDiagnostics::error(const TSourceLoc &loc,
const char *reason,
const char *token,
const char *extraInfo)
{
pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line;
writeInfo(pp::Diagnostics::PP_ERROR, srcLoc, reason, token, extraInfo);
}
void TDiagnostics::warning(const TSourceLoc &loc,
const char *reason,
const char *token,
const char *extraInfo)
{
pp::SourceLocation srcLoc;
srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line;
writeInfo(pp::Diagnostics::PP_WARNING, srcLoc, reason, token, extraInfo);
}
void TDiagnostics::print(ID id, void TDiagnostics::print(ID id,
const pp::SourceLocation& loc, const pp::SourceLocation& loc,
const std::string& text) const std::string& text)
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "compiler/preprocessor/DiagnosticsBase.h" #include "compiler/preprocessor/DiagnosticsBase.h"
class TInfoSink; class TInfoSink;
struct TSourceLoc;
class TDiagnostics : public pp::Diagnostics, angle::NonCopyable class TDiagnostics : public pp::Diagnostics, angle::NonCopyable
{ {
...@@ -29,6 +30,12 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable ...@@ -29,6 +30,12 @@ class TDiagnostics : public pp::Diagnostics, angle::NonCopyable
const std::string& token, const std::string& token,
const std::string& extra); const std::string& extra);
void error(const TSourceLoc &loc, const char *reason, const char *token, const char *extraInfo);
void warning(const TSourceLoc &loc,
const char *reason,
const char *token,
const char *extraInfo);
protected: protected:
void print(ID id, const pp::SourceLocation &loc, const std::string &text) override; void print(ID id, const pp::SourceLocation &loc, const std::string &text) override;
......
...@@ -141,10 +141,7 @@ void TParseContext::error(const TSourceLoc &loc, ...@@ -141,10 +141,7 @@ void TParseContext::error(const TSourceLoc &loc,
const char *token, const char *token,
const char *extraInfo) const char *extraInfo)
{ {
pp::SourceLocation srcLoc; mDiagnostics.error(loc, reason, token, extraInfo);
srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line;
mDiagnostics.writeInfo(pp::Diagnostics::PP_ERROR, srcLoc, reason, token, extraInfo);
} }
void TParseContext::warning(const TSourceLoc &loc, void TParseContext::warning(const TSourceLoc &loc,
...@@ -152,10 +149,7 @@ void TParseContext::warning(const TSourceLoc &loc, ...@@ -152,10 +149,7 @@ void TParseContext::warning(const TSourceLoc &loc,
const char *token, const char *token,
const char *extraInfo) const char *extraInfo)
{ {
pp::SourceLocation srcLoc; mDiagnostics.warning(loc, reason, token, extraInfo);
srcLoc.file = loc.first_file;
srcLoc.line = loc.first_line;
mDiagnostics.writeInfo(pp::Diagnostics::PP_WARNING, srcLoc, reason, token, extraInfo);
} }
void TParseContext::outOfRangeError(bool isError, void TParseContext::outOfRangeError(bool isError,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment