forked from metthal/IFJ-Projekt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnierr.h
112 lines (101 loc) · 2.71 KB
/
nierr.h
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ13.
*
* Codename:
* INI: Ni Interpreter
*
* Description:
* https://wis.fit.vutbr.cz/FIT/st/course-files-st.php/course/IFJ-IT/projects/ifj2013.pdf
*
* Project's GitHub repository:
* https://github.com/metthal/IFJ-Projekt
*
* Team:
* Marek Milkovič (xmilko01)
* Lukáš Vrabec (xvrabe07)
* Ján Spišiak (xspisi03)
* Ivan Ševčík (xsevci50)
* Marek Bertovič (xberto00)
*/
/**
* @file nierr.h
* @brief Declares error framework.
*/
#ifndef NIERR_H
#define NIERR_H
#include <stdio.h>
/*
* Add new values to enum as needed, but remember that those are error
* codes of interpreter thus at higher abstraction level. E.g. we don't need
* information that file doesn't exist, just that lexical analyzer had problem
* related to file, which can also be caused by missing <?php tag etc.
*/
/** Error types used internally to detect and handle errors. */
typedef enum
{
ERR_None = 0, //!< ERR_None
ERR_Unknown, //!< ERR_Unknown
ERR_LexFile, //!< ERR_LexFile
ERR_Allocation, //!< ERR_Allocation
ERR_Range, //!< ERR_Range
ERR_Internal, //!< ERR_Internal
ERR_Convert, //!< ERR_Convert
ERR_Syntax, //!< ERR_Syntax
ERR_UndefFunction, //!< ERR_UndefFunction
ERR_RedefFunction, //!< ERR_RedefFunction
ERR_UndefVariable, //!< ERR_UndefVariable
ERR_RedefParameter,//!< ERR_RedefParameter
ERR_BadParamCount, //!< ERR_BadParamCount
ERR_DefArgOrder, //!< ERR_DefArgOrder
ERR_BadDefArg, //!< ERR_BadDefArg
ERR_ISTGenerator, //!< ERR_ISTGenerator
ERR_CycleControl, //!< Invalid break / continue statement
ERR_Substr, //!< ERR_Substr
ERR_OperandTypes, //!< ERR_OperandTypes
ERR_DivideByZero //!< ERR_DivideByZero
} NiErrorType;
/** Structure that holds informations about error. */
typedef struct
{
NiErrorType type;
int line;
const char *file;
const char *fun;
} NiError;
#ifdef DEBUG
extern char errorPrinted;
void printError();
#endif
extern NiError niErr;
/** Gets last interpret error.
* @return Last error.
*/
static inline NiErrorType getError()
{
#ifdef DEBUG
printError();
#endif
return niErr.type;
}
/** Sets interpret error.
* @param err One of NiErrorType values.
*/
#define setError(err) setErrorExp(err, __LINE__, __FILE__, __func__)
static inline void setErrorExp(NiErrorType errType, int line, const char *file,
const char *fun)
{
niErr.type = errType;
niErr.line = line;
niErr.file = file;
niErr.fun = fun;
#ifdef DEBUG
errorPrinted = 0;
#endif
}
/** Clears interpret error to ERR_None */
static inline void clearError()
{
niErr.type = ERR_None;
}
#endif