This repository has been archived by the owner on Mar 16, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
error.h
107 lines (91 loc) · 2.19 KB
/
error.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
/*
* Project name:
* Implementace interpretu imperativního jazyka IFJ14
*
* Repository:
* https://github.com/Dasio/IFJ
*
* Team:
* Dávid Mikuš (xmikus15)
* Peter Hostačný (xhosta03)
* Tomáš Kello (xkello00)
* Adam Lučanský (xlucan01)
* Michaela Lukášová (xlukas09)
*/
#ifndef ERROR_H
#define ERROR_H
#include <stdio.h>
#define setError(state) setErrorDetails(state, __LINE__, __FILE__);
/**
* Enumeration for errors that could occur.
* !!! ADD ERROR STATE ALSO TO error.c IN returnCodeTable[]
* with appropriate return code.
*/
typedef enum
{
ERR_None = 0,
ERR_Allocation,
ERR_CannotOpenFile, /**< Occurs when IStream cannot open file */
// Lexical analysis
ERR_Lexical, /**< Generic lexical analysis error */
ERR_LexicalConversion, /**< String -> Real/Integer conversion failure */
// Parser
ERR_Syntax,
ERR_RedefVar,
ERR_RedefFunc,
ERR_DeclrFunc,
ERR_BadDefArg,
ERR_NoDefFunc, /**< Function was declared and no defintion was found */
ERR_ReadBool,
ERR_VarAsFunc,
ERR_FuncAsVar,
// Expression
ERR_SyntaxExpr,
ERR_PrecedenceTable,
ERR_Reduction,
ERR_TypeCompatibility,
ERR_TypeCompatibilityArg,
ERR_UndefVarOrFunction,
ERR_ArgCount,
// Interpreter
ERR_UnknownInstruction,
ERR_UnitializedAccess,
ERR_DivisionByZero,
ERR_ReadInput,
// Other
ERR_OutOfRange,
ERR_Unknown,
} EErrorStates;
/** Structure that holds information about error */
typedef struct
{
EErrorStates state; /**< Which error occured */
unsigned line; /**< At which line error occured */
char *file; /**< In which file error occured */
} SError;
/**
* Prints to stderr last error
*/
void printError();
/**
* Prints in which file and line was error
* @param description Description of error
*/
void printErrorDetails(const char *description);
/**
* Sets error details based on where macro setError was called
* @param state Type of error
* @param line At which line error occured
* @param file In which file error occured
*/
void setErrorDetails(EErrorStates state, unsigned line, char *file);
/**
* @return lastError
*/
EErrorStates getError();
/**
* Returns bash return code according to state
* @return Return code
*/
int getReturnError();
#endif