forked from adnanis78612/mana-script
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherror.cpp
More file actions
66 lines (53 loc) · 1.99 KB
/
error.cpp
File metadata and controls
66 lines (53 loc) · 1.99 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
61
62
63
64
65
66
// Adding error.cpp from manu-r12
#include "error.hpp"
#include <sstream>
namespace mana {
// Initialize the global diagnostic manager
DiagnosticManager diagnostics;
std::string SourceLocation::toString() const {
std::stringstream ss;
if (!filename.empty()) {
ss << filename << ":";
}
ss << line << ":" << column;
return ss.str();
}
std::string Diagnostic::toString() const {
std::string severity_str;
switch (severity) {
case DiagnosticSeverity::INFO: severity_str = "info"; break;
case DiagnosticSeverity::WARNING: severity_str = "warning"; break;
case DiagnosticSeverity::ERROR: severity_str = "error"; break;
case DiagnosticSeverity::FATAL: severity_str = "fatal error"; break;
default: severity_str = "unknown"; break;
}
std::stringstream ss;
ss << location.toString() << ": " << severity_str << ": " << message;
if (!code_context.empty()) {
ss << "\n" << code_context;
// Add a caret pointing to the column position
if (location.column > 0) {
ss << "\n" << std::string(location.column - 1, ' ') << "^";
}
}
return ss.str();
}
void DiagnosticManager::report(const Diagnostic& diagnostic) {
diagnostics.push_back(diagnostic);
if (diagnostic.getSeverity() == DiagnosticSeverity::ERROR ||
diagnostic.getSeverity() == DiagnosticSeverity::FATAL) {
has_errors = true;
}
}
void DiagnosticManager::report(DiagnosticSeverity severity,
const std::string& message,
const SourceLocation& location,
const std::string& code_context) {
report(Diagnostic(severity, message, location, code_context));
}
void DiagnosticManager::printDiagnostics(std::ostream& os) const {
for (const auto& diagnostic : diagnostics) {
os << diagnostic.toString() << std::endl;
}
}
} // namespace mana// Adding error.cpp from manu-r12