-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.c
105 lines (97 loc) · 2.68 KB
/
errors.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
102
103
104
105
//
// errors.c
// Oberon
//
// Created by Alvaro Costa Neto on 10/15/13.
// Copyright (c) 2013 Alvaro Costa Neto. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "scanner.h"
#include "errors.h"
#define ERRORS_BAD_CODE_TOLERANCE 50
unsigned int errors_count = 0;
// Esta função aponta que um erro aconteceu usando a mensagem de parâmetro
void mark_at(const error_t error, const position_t position, const char *message, ...)
{
if (error > error_warning)
errors_count++;
if (errors_count > ERRORS_BAD_CODE_TOLERANCE) {
printf("%d errors? That's it. I quit!\n", ERRORS_BAD_CODE_TOLERANCE);
exit(EXIT_FAILURE);
}
switch (error) {
case error_log:
printf("Log at "); break;
case error_info:
printf("Info at "); break;
case error_tip:
printf("Tip at "); break;
case error_warning:
printf("Warning at "); break;
case error_scanner:
printf("Error at "); break;
case error_parser:
printf("Error at "); break;
case error_fatal:
printf("What are you freaking doing? "); break;
default:
printf("Whaaaaaat?! at "); break;
}
printf("(%d, %d): ", position.line, position.column);
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
printf("\n");
if (error == error_fatal)
exit(EXIT_FAILURE);
}
// TODO: Evitar duplicação de código!
void mark(const error_t error, const char *message, ...)
{
if (error > error_warning)
errors_count++;
if (errors_count > ERRORS_BAD_CODE_TOLERANCE) {
printf("%d errors? That's it. I quit!\n", ERRORS_BAD_CODE_TOLERANCE);
exit(EXIT_FAILURE);
}
switch (error) {
case error_log:
printf("Log at "); break;
case error_info:
printf("Info at "); break;
case error_tip:
printf("Tip at "); break;
case error_warning:
printf("Warning at "); break;
case error_scanner:
printf("Error at "); break;
case error_parser:
printf("Error at "); break;
case error_fatal:
printf("What are you freaking doing? "); break;
default:
printf("Whaaaaaat?! at "); break;
}
printf("(%d, %d): ", current_token.position.line, current_token.position.column);
va_list args;
va_start(args, message);
vprintf(message, args);
va_end(args);
printf("\n");
if (error == error_fatal)
exit(EXIT_FAILURE);
}
void mark_missing(symbol_t symbol)
{
if (symbol == symbol_id)
mark(error_parser, "Missing identifier.");
else if (symbol == symbol_integer)
mark(error_parser, "Missing integer.");
else if (symbol == symbol_real)
mark(error_parser, "Missing real.");
else
mark(error_parser, "Missing \"%s\".", id_for_symbol(symbol));
}