1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 17:29:55 +00:00
openmw/components/compiler/streamerrorhandler.cpp
florent.teppe 42e45723b7 Fixes issue in MW script compilation that would silently produce the wrong bytecode
Fixes issue when fetching MyGui values that were stored as RefId but fetched as String

Removed some uncessary copies, fixed issues with lowercase and uneeded changes
2022-12-27 19:15:57 +01:00

75 lines
1.8 KiB
C++

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