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