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

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

76 lines
1.8 KiB
C++
Raw Normal View History

2010-06-27 17:20:21 +00:00
#include "streamerrorhandler.hpp"
#include <sstream>
#include <components/debug/debuglog.hpp>
2010-06-27 17:20:21 +00:00
#include "tokenloc.hpp"
namespace Compiler
{
// Report error to the user.
2022-09-22 18:26:05 +00:00
void StreamErrorHandler::report(const std::string& message, const TokenLoc& loc, Type type)
2010-06-27 17:20:21 +00:00
{
Debug::Level logLevel = Debug::Info; // Usually script warnings are not too important
if (type == ErrorMessage)
logLevel = Debug::Error;
std::stringstream text;
2022-09-22 18:26:05 +00:00
if (type == ErrorMessage)
text << "Error: ";
2010-06-27 17:20:21 +00:00
else
text << "Warning: ";
2010-06-27 17:20:21 +00:00
if (!mContext.empty())
text << mContext << " ";
2022-09-22 18:26:05 +00:00
text << "line " << loc.mLine + 1 << ", column " << loc.mColumn + 1 << " (" << loc.mLiteral << "): " << message;
Log(logLevel) << text.str();
2010-06-27 17:20:21 +00:00
}
// Report a file related error
2022-09-22 18:26:05 +00:00
void StreamErrorHandler::report(const std::string& message, Type type)
2010-06-27 17:20:21 +00:00
{
Debug::Level logLevel = Debug::Info;
2022-09-22 18:26:05 +00:00
if (type == ErrorMessage)
logLevel = Debug::Error;
std::stringstream text;
2022-09-22 18:26:05 +00:00
if (type == ErrorMessage)
text << "Error: ";
2010-06-27 17:20:21 +00:00
else
text << "Warning: ";
if (!mContext.empty())
text << mContext << " ";
text << "file: " << message << std::endl;
2010-06-27 17:20:21 +00:00
Log(logLevel) << text.str();
2010-06-27 17:20:21 +00:00
}
2022-09-22 18:26:05 +00:00
void StreamErrorHandler::setContext(const std::string& context)
{
mContext = context;
}
StreamErrorHandler::StreamErrorHandler() = default;
2020-04-02 18:14:52 +00:00
2022-09-22 18:26:05 +00:00
ContextOverride::ContextOverride(StreamErrorHandler& handler, const std::string& context)
: mHandler(handler)
, mContext(handler.mContext)
2020-04-02 18:27:52 +00:00
{
2020-04-04 12:09:00 +00:00
mHandler.setContext(context);
2020-04-02 18:27:52 +00:00
}
2020-04-04 12:09:00 +00:00
ContextOverride::~ContextOverride()
2020-04-02 18:14:52 +00:00
{
2020-04-04 12:09:00 +00:00
mHandler.setContext(mContext);
2020-04-02 18:14:52 +00:00
}
}