1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-05 15:55:45 +00:00
OpenMW/components/compiler/errorhandler.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

103 lines
2.1 KiB
C++
Raw Normal View History

2010-06-27 17:20:21 +00:00
#include "errorhandler.hpp"
namespace Compiler
{
ErrorHandler::ErrorHandler()
2022-09-22 18:26:05 +00:00
: mWarnings(0)
, mErrors(0)
, mWarningsMode(1)
, mDowngradeErrors(false)
{
}
2010-06-27 17:20:21 +00:00
ErrorHandler::~ErrorHandler() = default;
2010-06-27 17:20:21 +00:00
// Was compiling successful?
bool ErrorHandler::isGood() const
{
2022-09-22 18:26:05 +00:00
return mErrors == 0;
2010-06-27 17:20:21 +00:00
}
// Return number of errors
int ErrorHandler::countErrors() const
{
return mErrors;
}
// Return number of warnings
int ErrorHandler::countWarnings() const
{
return mWarnings;
}
// Generate a warning message.
2022-09-22 18:26:05 +00:00
void ErrorHandler::warning(const std::string& message, const TokenLoc& loc)
2010-06-27 17:20:21 +00:00
{
2022-09-22 18:26:05 +00:00
if (mWarningsMode == 1 ||
// temporarily change from mode 2 to mode 1 if error downgrading is enabled to
// avoid infinite recursion
2022-09-22 18:26:05 +00:00
(mWarningsMode == 2 && mDowngradeErrors))
{
++mWarnings;
2022-09-22 18:26:05 +00:00
report(message, loc, WarningMessage);
}
2022-09-22 18:26:05 +00:00
else if (mWarningsMode == 2)
error(message, loc);
2010-06-27 17:20:21 +00:00
}
// Generate an error message.
2022-09-22 18:26:05 +00:00
void ErrorHandler::error(const std::string& message, const TokenLoc& loc)
2010-06-27 17:20:21 +00:00
{
if (mDowngradeErrors)
{
2022-09-22 18:26:05 +00:00
warning(message, loc);
return;
}
2010-06-27 17:20:21 +00:00
++mErrors;
2022-09-22 18:26:05 +00:00
report(message, loc, ErrorMessage);
2010-06-27 17:20:21 +00:00
}
// Generate an error message for an unexpected EOF.
void ErrorHandler::endOfFile()
{
++mErrors;
2022-09-22 18:26:05 +00:00
report("unexpected end of file", ErrorMessage);
2010-06-27 17:20:21 +00:00
}
// Remove all previous error/warning events
void ErrorHandler::reset()
{
mErrors = mWarnings = 0;
}
2022-09-22 18:26:05 +00:00
void ErrorHandler::setWarningsMode(int mode)
{
mWarningsMode = mode;
}
2022-09-22 18:26:05 +00:00
void ErrorHandler::downgradeErrors(bool downgrade)
{
mDowngradeErrors = downgrade;
}
2022-09-22 18:26:05 +00:00
ErrorDowngrade::ErrorDowngrade(ErrorHandler& handler)
: mHandler(handler)
{
2022-09-22 18:26:05 +00:00
mHandler.downgradeErrors(true);
}
ErrorDowngrade::~ErrorDowngrade()
{
2022-09-22 18:26:05 +00:00
mHandler.downgradeErrors(false);
}
2010-06-27 17:20:21 +00:00
}