mini-llvm 0.1.0
Loading...
Searching...
No Matches
Diagnostic.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstddef>
6#include <cstdlib>
7#include <string>
8#include <utility>
9
11
12namespace mini_llvm {
13
14struct Diagnostic {
15 enum class Level {
19 };
20
22 std::string message;
23 size_t location;
24
25 static Diagnostic note(std::string message, size_t location) {
26 return {Level::kNote, std::move(message), location};
27 }
28
29 static Diagnostic warning(std::string message, size_t location) {
30 return {Level::kWarning, std::move(message), location};
31 }
32
33 static Diagnostic error(std::string message, size_t location) {
34 return {Level::kError, std::move(message), location};
35 }
36};
37
38inline constexpr const char *name(Diagnostic::Level level) {
39 using enum Diagnostic::Level;
40 switch (level) {
41 case kNote: return "note";
42 case kWarning: return "warning";
43 case kError: return "error";
44 default: abort();
45 }
46}
47
49 using enum Diagnostic::Level;
50 using namespace colors;
51 switch (level) {
52 case kNote: return cyan;
53 case kWarning: return magenta;
54 case kError: return red;
55 default: abort();
56 }
57}
58
59} // namespace mini_llvm
Definition Color.h:97
Definition Color.h:170
Definition GraphColoringAllocator.h:13
constexpr const char * name(Diagnostic::Level level)
Definition Diagnostic.h:38
Color color(Diagnostic::Level level)
Definition Diagnostic.h:48
Definition Diagnostic.h:14
std::string message
Definition Diagnostic.h:22
static Diagnostic error(std::string message, size_t location)
Definition Diagnostic.h:33
Level level
Definition Diagnostic.h:21
static Diagnostic warning(std::string message, size_t location)
Definition Diagnostic.h:29
size_t location
Definition Diagnostic.h:23
static Diagnostic note(std::string message, size_t location)
Definition Diagnostic.h:25
Level
Definition Diagnostic.h:15
@ kError
Definition Diagnostic.h:18
@ kWarning
Definition Diagnostic.h:17
@ kNote
Definition Diagnostic.h:16