forked from metthal/IFJ-Projekt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rc.h
106 lines (90 loc) · 2.78 KB
/
rc.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
/*
* 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 rc.h
* @author INI Team
*
* @brief Result codes and everything about application termination
**/
#ifndef RC_H
#define RC_H
#include "nierr.h"
/**
* @enum ResultCode
*
* Result or exit codes of the application as defined by assignment
*
* @todo Remove @ref RC_Unknown before submission, just internal
**/
typedef enum
{
RC_Ok = 0, ///< Successful intepretation
RC_LexError = 1, ///< Lexical analysis error
RC_SynError = 2, ///< Syntax analysis error
RC_FuncDefError = 3, ///< Semantic error - function undefined / redefined
RC_FuncParamError = 4, ///< Semantic/runtime error - wrong parameters on function call
RC_VarError = 5, ///< Semantic/runtime error - variable not declared
RC_DivByZero = 10, ///< Semantic/runtime error - division by zero
RC_NumCastError = 11, ///< Semantic/runtime error - error in casting to number (function doubleval)
RC_ArithmError = 12, ///< Semantic/runtime error - type compatibility in arithmetic expressions
RC_UnkError = 13, ///< Semantic/runtime error - Other errors
RC_FatalError = 99 ///< Error not related to interpreter (bad allocation etc)
} ResultCode;
/**
* Transforms @ref NiErrorType into @ref ResultCode
*
* @return Result code of corresponding error type
**/
static inline ResultCode getRcFromError()
{
switch (niErr.type) {
case ERR_None:
return RC_Ok;
case ERR_LexFile:
return RC_LexError;
case ERR_Syntax:
case ERR_CycleControl:
case ERR_BadDefArg:
return RC_SynError;
case ERR_Allocation:
return RC_FatalError;
case ERR_Convert:
return RC_NumCastError;
case ERR_UndefFunction:
case ERR_RedefFunction:
return RC_FuncDefError;
case ERR_UndefVariable:
return RC_VarError;
case ERR_BadParamCount:
case ERR_DefArgOrder:
return RC_FuncParamError;
case ERR_RedefParameter:
case ERR_Substr:
return RC_UnkError;
case ERR_OperandTypes:
return RC_ArithmError;
case ERR_DivideByZero:
return RC_DivByZero;
default:
return RC_FatalError;
}
}
#endif