Use the logging system for compiler errors

pull/541/head
Andrei Kortunov 6 years ago
parent 2cc359a205
commit bd2188a0f8

@ -50,8 +50,7 @@ namespace MWDialogue
DialogueManager::DialogueManager (const Compiler::Extensions& extensions, Translation::Storage& translationDataStorage) : DialogueManager::DialogueManager (const Compiler::Extensions& extensions, Translation::Storage& translationDataStorage) :
mTranslationDataStorage(translationDataStorage) mTranslationDataStorage(translationDataStorage)
, mCompilerContext (MWScript::CompilerContext::Type_Dialogue) , mCompilerContext (MWScript::CompilerContext::Type_Dialogue)
, mErrorStream(std::cout.rdbuf()) , mErrorHandler()
, mErrorHandler(mErrorStream)
, mTalkedTo(false) , mTalkedTo(false)
, mTemporaryDispositionChange(0.f) , mTemporaryDispositionChange(0.f)
, mPermanentDispositionChange(0.f) , mPermanentDispositionChange(0.f)
@ -204,8 +203,7 @@ namespace MWDialogue
if (!success) if (!success)
{ {
Log(Debug::Warning) Log(Debug::Error) << "Error: compiling failed (dialogue script): \n" << cmd << "\n";
<< "Warning: compiling failed (dialogue script)\n" << cmd << "\n\n";
} }
return success; return success;

@ -33,7 +33,6 @@ namespace MWDialogue
Translation::Storage& mTranslationDataStorage; Translation::Storage& mTranslationDataStorage;
MWScript::CompilerContext mCompilerContext; MWScript::CompilerContext mCompilerContext;
std::ostream mErrorStream;
Compiler::StreamErrorHandler mErrorHandler; Compiler::StreamErrorHandler mErrorHandler;
MWWorld::Ptr mActor; MWWorld::Ptr mActor;

@ -28,8 +28,7 @@ void test(const MWWorld::Ptr& actor, int &compiled, int &total, const Compiler::
MWScript::CompilerContext compilerContext(MWScript::CompilerContext::Type_Dialogue); MWScript::CompilerContext compilerContext(MWScript::CompilerContext::Type_Dialogue);
compilerContext.setExtensions(extensions); compilerContext.setExtensions(extensions);
std::ostream errorStream(std::cout.rdbuf()); Compiler::StreamErrorHandler errorHandler;
Compiler::StreamErrorHandler errorHandler(errorStream);
errorHandler.setWarningsMode (warningsMode); errorHandler.setWarningsMode (warningsMode);
const MWWorld::Store<ESM::Dialogue>& dialogues = MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>(); const MWWorld::Store<ESM::Dialogue>& dialogues = MWBase::Environment::get().getWorld()->getStore().get<ESM::Dialogue>();
@ -84,8 +83,7 @@ void test(const MWWorld::Ptr& actor, int &compiled, int &total, const Compiler::
if (!success) if (!success)
{ {
Log(Debug::Warning) Log(Debug::Error) << "Error: compiling failed (dialogue script): \n" << info->mResultScript << "\n";
<< "compiling failed (dialogue script)\n" << info->mResultScript << "\n\n";
} }
} }
} }

@ -25,7 +25,7 @@ namespace MWScript
ScriptManager::ScriptManager (const MWWorld::ESMStore& store, ScriptManager::ScriptManager (const MWWorld::ESMStore& store,
Compiler::Context& compilerContext, int warningsMode, Compiler::Context& compilerContext, int warningsMode,
const std::vector<std::string>& scriptBlacklist) const std::vector<std::string>& scriptBlacklist)
: mErrorHandler (std::cerr), mStore (store), : mErrorHandler(), mStore (store),
mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext), mCompilerContext (compilerContext), mParser (mErrorHandler, mCompilerContext),
mOpcodesInstalled (false), mGlobalScripts (store) mOpcodesInstalled (false), mGlobalScripts (store)
{ {
@ -72,8 +72,7 @@ namespace MWScript
if (!Success) if (!Success)
{ {
Log(Debug::Warning) Log(Debug::Error) << "Error: script compiling failed: " << name;
<< "Warning: compiling failed: " << name;
} }
if (Success) if (Success)

@ -1,5 +1,9 @@
#include "streamerrorhandler.hpp" #include "streamerrorhandler.hpp"
#include <sstream>
#include <components/debug/debuglog.hpp>
#include "tokenloc.hpp" #include "tokenloc.hpp"
namespace Compiler namespace Compiler
@ -9,32 +13,47 @@ namespace Compiler
void StreamErrorHandler::report (const std::string& message, const TokenLoc& loc, void StreamErrorHandler::report (const std::string& message, const TokenLoc& loc,
Type type) 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) if (type==ErrorMessage)
mStream << "error "; text << "Error: ";
else else
mStream << "warning "; text << "Warning: ";
if (!mContext.empty()) if (!mContext.empty())
mStream << mContext << " "; text << mContext << " ";
text << "line " << loc.mLine+1 << ", column " << loc.mColumn+1
<< " (" << loc.mLiteral << "): " << message;
mStream Log(logLevel) << text.str();
<< "line " << loc.mLine+1 << ", column " << loc.mColumn+1
<< " (" << loc.mLiteral << ")" << std::endl
<< " " << message << std::endl;
} }
// Report a file related error // Report a file related error
void StreamErrorHandler::report (const std::string& message, Type type) void StreamErrorHandler::report (const std::string& message, Type type)
{ {
Debug::Level logLevel = Debug::Info;
if (type==ErrorMessage) if (type==ErrorMessage)
mStream << "error "; logLevel = Debug::Error;
std::stringstream text;
if (type==ErrorMessage)
text << "Error: ";
else else
mStream << "warning "; text << "Warning: ";
if (!mContext.empty())
text << mContext << " ";
text << "file: " << message << std::endl;
mStream Log(logLevel) << text.str();
<< "file:" << std::endl
<< " " << message << std::endl;
} }
void StreamErrorHandler::setContext(const std::string &context) void StreamErrorHandler::setContext(const std::string &context)
@ -42,5 +61,5 @@ namespace Compiler
mContext = context; mContext = context;
} }
StreamErrorHandler::StreamErrorHandler (std::ostream& ErrorStream) : mStream (ErrorStream) {} StreamErrorHandler::StreamErrorHandler() {}
} }

@ -7,12 +7,10 @@
namespace Compiler namespace Compiler
{ {
/// \brief Error handler implementation: Write errors into stream /// \brief Error handler implementation: Write errors into logging stream
class StreamErrorHandler : public ErrorHandler class StreamErrorHandler : public ErrorHandler
{ {
std::ostream& mStream;
std::string mContext; std::string mContext;
// not implemented // not implemented
@ -32,7 +30,7 @@ namespace Compiler
// constructors // constructors
StreamErrorHandler (std::ostream& ErrorStream); StreamErrorHandler ();
///< constructor ///< constructor
}; };
} }

Loading…
Cancel
Save