ACSE 2.0.3
Advanced Compiler System for Education
Loading...
Searching...
No Matches
errors.c
Go to the documentation of this file.
1
3
4#include <stdio.h>
5#include <stdlib.h>
6#include <stdarg.h>
7#include "errors.h"
8
10
11
12static void printMessage(
13 t_fileLocation loc, const char *category, const char *fmt, va_list arg)
14{
15 if (loc.file && loc.row >= 0)
16 fprintf(stderr, "%s:%d: %s: ", loc.file, loc.row + 1, category);
17 else
18 fprintf(stderr, "%s: ", category);
19 vfprintf(stderr, fmt, arg);
20 fputc('\n', stderr);
21}
22
23void emitError(t_fileLocation loc, const char *fmt, ...)
24{
25 va_list args;
26 va_start(args, fmt);
27 printMessage(loc, "error", fmt, args);
28 va_end(args);
29 numErrors++;
30}
31
32void fatalError(const char *format, ...)
33{
34 va_list args;
35 va_start(args, format);
36 printMessage(nullFileLocation, "fatal error", format, args);
37 va_end(args);
38 exit(1);
39}
Error logging utilities.
char * file
The name of the file.
Definition errors.h:20
int row
The zero-based index of a line in the file.
Definition errors.h:21
void emitError(t_fileLocation loc, const char *fmt,...)
Definition errors.c:23
int numErrors
The number of errors logged by emitError up to now.
Definition errors.c:9
void fatalError(const char *format,...)
Definition errors.c:32
Structure that represents a location in a file.
Definition errors.h:19