File: errorhandler.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (89 lines) | stat: -rw-r--r-- 2,064 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#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;

    protected:
        enum Type
        {
            WarningMessage,
            ErrorMessage
        };

    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

    public:
        ErrorHandler();
        ///< constructor

        virtual ~ErrorHandler();
        ///< destructor

        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();
        ///< 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&);

    public:
        explicit ErrorDowngrade(ErrorHandler& handler);

        ~ErrorDowngrade();
    };
}

#endif