topazc
exception.cpp
Go to the documentation of this file.
1
6
8#include <iostream>
9
18 switch (type) {
19 case SUB_LEXER:
20 return "lexer";
21 case SUB_PARSER:
22 return "parser";
23 case SUB_SEMANTIC:
24 return "semantic";
25 case SUB_CODEGEN:
26 return "codegen";
27 }
28}
29
30void throw_exception(SubsystemType type, std::string msg, uint32_t line, std::string file_name, bool is_debug) {
31 if (is_debug) {
32 std::cerr << "\033[31mSubsystem \033[0m'" << convert_subsystem_type_to_string(type) << "'\033[31m handled the error\n";
33 }
34 std::cerr << "\033[31mCompilation error at:\033[0m " << file_name << ':' << line << "\n\033[31m" << msg << "\033[0m\n";
35 exit(1);
36}
std::string convert_subsystem_type_to_string(SubsystemType type)
Function for converting passed subsystem type into string.
Definition exception.cpp:17
void throw_exception(SubsystemType type, std::string msg, uint32_t line, std::string file_name, bool is_debug)
Function for throwing exception.
Definition exception.cpp:30
Header file for defining thrown exceptions by the compiler.
SubsystemType
Subsystem from which the exception throwed.
Definition exception.hpp:14
@ SUB_LEXER
Definition exception.hpp:15
@ SUB_PARSER
Definition exception.hpp:16
@ SUB_CODEGEN
Definition exception.hpp:18
@ SUB_SEMANTIC
Definition exception.hpp:17