| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | #pragma once
 | 
					
						
							|  |  |  | #include <exception>
 | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  | #include <optional>
 | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | #include "type.hpp"
 | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  | #include "location.hh"
 | 
					
						
							|  |  |  | #include "parse_driver.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using maybe_location = std::optional<yy::location>; | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-11 21:29:49 -07:00
										 |  |  | struct compiler_error : std::exception { | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  |     std::string description; | 
					
						
							| 
									
										
										
										
											2020-09-11 21:29:49 -07:00
										 |  |  |     maybe_location loc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     compiler_error(std::string d, maybe_location l = std::nullopt) | 
					
						
							|  |  |  |         : description(std::move(d)), loc(std::move(l)) {} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const char* what() const noexcept override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void print_about(std::ostream& to); | 
					
						
							| 
									
										
										
										
											2020-09-15 18:51:28 -07:00
										 |  |  |     void print_location(std::ostream& to, file_mgr& fm, bool highlight = false); | 
					
						
							| 
									
										
										
										
											2020-09-11 21:29:49 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 18:51:28 -07:00
										 |  |  |     void pretty_print(std::ostream& to, file_mgr& fm); | 
					
						
							| 
									
										
										
										
											2020-09-11 21:29:49 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct type_error : compiler_error { | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  |     std::optional<yy::location> loc; | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  |     type_error(std::string d, maybe_location l = std::nullopt) | 
					
						
							| 
									
										
										
										
											2020-09-11 21:29:49 -07:00
										 |  |  |         : compiler_error(std::move(d), std::move(l)) {} | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const char* what() const noexcept override; | 
					
						
							| 
									
										
										
										
											2020-09-15 18:51:28 -07:00
										 |  |  |     void pretty_print(std::ostream& to, file_mgr& fm); | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct unification_error : public type_error { | 
					
						
							|  |  |  |     type_ptr left; | 
					
						
							|  |  |  |     type_ptr right; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  |     unification_error(type_ptr l, type_ptr r, maybe_location loc = std::nullopt) | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  |         : left(std::move(l)), right(std::move(r)),  | 
					
						
							| 
									
										
										
										
											2020-09-09 15:08:43 -07:00
										 |  |  |             type_error("failed to unify types", std::move(loc)) {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-15 18:51:28 -07:00
										 |  |  |     void pretty_print(std::ostream& to, file_mgr& fm, type_mgr& mgr); | 
					
						
							| 
									
										
										
										
											2020-09-08 18:38:05 -07:00
										 |  |  | }; |