-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherror.c
102 lines (92 loc) · 2.05 KB
/
error.c
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
/*********************************************
* Program : error.c
* Authors : Roman Dobiáš - xdobia11
* Adrián Tomašov - xtomas32
* Jozef Urbanovský - xurban66
* Adam Šulc - xsulca00
* Kristián Barna - xbarna02
* Skupina : 2BIB(2016)
* Created : 01.10.2016
* Compiled: gcc 4.9.2
* Project : IFJ16
*
* Notes : Implementation of global error module
********************************************/
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include "error.h"
#include "ial.h"
#include "interpret.h"
#ifndef TEST
#include "scanner.h"
#include "parser.h"
#include "op-parser.h"
#endif
extern stab_t* staticSym;
// Call module dtors
void clean_up()
{
#ifndef TEST
// TODO:
// scanner clean up
scanner_closeFile();
// parser clean up
parser_clean();
//clean interpret
interpret_clean();
opparser_clean();
#endif
}
// Exit the process with 'errtype' return value and cleanup resources before leaving
void errorLeave(int errtype)
{
clean_up();
exit(errtype);
}
const char* getErrorName(enum errorTypes type)
{
switch(type)
{
case SUCCESS_ERROR:
return "DONE";
case LEXICAL_ERROR:
return "LEXICAL";
case SYNTAX_ERROR:
return "SYNTAX";
case SEMANTIC_ERROR:
return "SEMANTIC";
case SEMANTIC_TYPE_ERROR:
return "SEM.TYPE";
case SEMANTIC_ERROR_REST:
return "SEM.REST";
case RUNTIME_READ_ERROR:
return "RT_READ";
case RUNTIME_UNINITIALIZED:
return "RT_UINIT";
case RUNTIME_NULLDIVISION:
return "RT_NULL";
case RUNTIME_ERROR:
return "RUNTIME";
case INTERNAL_ERROR:
return "INTERNAL";
default:
break;
}
return "UNK";
}
void error_and_die(enum errorTypes type, const char *fmt, ...)
{
if(type != SUCCESS_ERROR)
{
va_list valist;
va_start(valist, fmt);
#ifndef TEST
fprintf(stderr,"[%s][%d:%d] ",getErrorName(type),getTokLine(),getTokTabs());
#endif
vfprintf(stderr,fmt, valist);
fputc('\n',stderr);
va_end(valist);
}
errorLeave(type);
}