1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-15 22:49:48 +00:00
OpenMW/components/compiler/errorhandler.hpp

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

90 lines
2.0 KiB
C++
Raw Normal View History

2010-06-27 17:20:21 +00:00
#ifndef COMPILER_ERRORHANDLER_H_INCLUDED
#define COMPILER_ERRORHANDLER_H_INCLUDED
#include <string>
namespace Compiler
{
struct TokenLoc;
/// \brief Error handling
///
/// This class collects errors and provides an interface for reporting them to the user.
class ErrorHandler
{
int mWarnings;
int mErrors;
int mWarningsMode;
bool mDowngradeErrors;
2022-09-22 18:26:05 +00:00
2010-06-27 17:20:21 +00:00
protected:
enum Type
{
WarningMessage,
ErrorMessage
};
2022-09-22 18:26:05 +00:00
2010-06-27 17:20:21 +00:00
private:
// mutators
virtual void report(const std::string& message, const TokenLoc& loc, Type type) = 0;
///< Report error to the user.
virtual void report(const std::string& message, Type type) = 0;
///< Report a file related error
2022-09-22 18:26:05 +00:00
public:
2010-06-27 17:20:21 +00:00
ErrorHandler();
2011-01-05 21:18:21 +00:00
///< constructor
2010-06-27 17:20:21 +00:00
virtual ~ErrorHandler();
2011-01-05 21:18:21 +00:00
///< destructor
2010-06-27 17:20:21 +00:00
bool isGood() const;
///< Was compiling successful?
int countErrors() const;
///< Return number of errors
int countWarnings() const;
///< Return number of warnings
void warning(const std::string& message, const TokenLoc& loc);
///< Generate a warning message.
void error(const std::string& message, const TokenLoc& loc);
///< Generate an error message.
void endOfFile();
///< Generate an error message for an unexpected EOF.
virtual void reset();
2010-06-27 17:20:21 +00:00
///< Remove all previous error/warning events
void setWarningsMode(int mode);
///< // 0 ignore, 1 rate as warning, 2 rate as error
/// Treat errors as warnings.
void downgradeErrors(bool downgrade);
};
class ErrorDowngrade
{
ErrorHandler& mHandler;
/// not implemented
ErrorDowngrade(const ErrorDowngrade&);
/// not implemented
ErrorDowngrade& operator=(const ErrorDowngrade&);
2022-09-22 18:26:05 +00:00
public:
explicit ErrorDowngrade(ErrorHandler& handler);
~ErrorDowngrade();
2010-06-27 17:20:21 +00:00
};
}
#endif