1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-31 02:45:34 +00:00
openmw/components/compiler/errorhandler.hpp

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