-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.cc
More file actions
60 lines (47 loc) · 1.38 KB
/
Copy patherrors.cc
File metadata and controls
60 lines (47 loc) · 1.38 KB
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
/**
* File: errors.cc
* ---------------
* Implementation for error-reporting class.
*/
#include "errors.h"
#include <iostream>
#include <sstream>
#include <stdarg.h>
#include <stdio.h>
using namespace std;
int ReportError::numErrors = 0;
void ReportError::OutputError(yyltype *loc, string msg) {
numErrors++;
fflush(stdout); // make sure any buffered text has been output
if (loc) {
cerr << endl << "*** Error line " << loc->first_line << "." << endl;
} else
cerr << endl << "*** Error." << endl;
cerr << "*** " << msg << endl << endl;
}
void ReportError::Formatted(yyltype *loc, const char *format, ...) {
va_list args;
char errbuf[2048];
va_start(args, format);
vsprintf(errbuf,format, args);
va_end(args);
OutputError(loc, errbuf);
}
void ReportError::UntermComment() {
OutputError(NULL, "Input ends with unterminated comment");
}
void ReportError::LongIdentifier(yyltype *loc, const char *ident) {
ostringstream s;
s << "Identifier too long: \"" << ident << "\"";
OutputError(loc, s.str());
}
void ReportError::UntermString(yyltype *loc, const char *str) {
ostringstream s;
s << "Unterminated string constant: " << str;
OutputError(loc, s.str());
}
void ReportError::UnrecogChar(yyltype *loc, char ch) {
ostringstream s;
s << "Unrecognized char: '" << ch << "'";
OutputError(loc, s.str());
}