| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #pragma once | ||
| 4 | |||
| 5 | #include <exception> | ||
| 6 | #include <string> | ||
| 7 | |||
| 8 | #include <Token.h> | ||
| 9 | |||
| 10 | namespace spice::compiler { | ||
| 11 | |||
| 12 | // Forward declarations | ||
| 13 | struct CodeLoc; | ||
| 14 | |||
| 15 | enum CompilerErrorType : uint8_t { | ||
| 16 | UNRESOLVED_SOFT_ERRORS, | ||
| 17 | SOURCE_FILE_NOT_FOUND, | ||
| 18 | CANT_OPEN_OUTPUT_FILE, | ||
| 19 | WRONG_OUTPUT_TYPE, | ||
| 20 | INTERNAL_ERROR, | ||
| 21 | IO_ERROR, | ||
| 22 | STD_NOT_FOUND, | ||
| 23 | BOOTSTRAP_NOT_FOUND, | ||
| 24 | UNHANDLED_BRANCH, | ||
| 25 | TYPE_CHECKER_RUNS_EXCEEDED, | ||
| 26 | TARGET_NOT_AVAILABLE, | ||
| 27 | OOM, | ||
| 28 | INVALID_FUNCTION, | ||
| 29 | INVALID_MODULE | ||
| 30 | }; | ||
| 31 | |||
| 32 | /** | ||
| 33 | * Custom exception for errors, occurring in the general context of the compiler | ||
| 34 | */ | ||
| 35 | class CompilerError final : public std::exception { | ||
| 36 | public: | ||
| 37 | // Constructors | ||
| 38 | CompilerError(const CompilerErrorType &type, const std::string &message); | ||
| 39 | CompilerError(const CodeLoc &codeLoc, const CompilerErrorType &type, const std::string &message); | ||
| 40 | |||
| 41 | // Public methods | ||
| 42 | [[nodiscard]] const char *what() const noexcept override; | ||
| 43 | [[nodiscard]] static std::string getMessagePrefix(CompilerErrorType errorType); | ||
| 44 | |||
| 45 | // Public members | ||
| 46 | std::string errorMessage; | ||
| 47 | }; | ||
| 48 | |||
| 49 | } // namespace spice::compiler | ||
| 50 |