GCC Code Coverage Report


Directory: ../
File: src/exception/CompilerError.cpp
Date: 2025-10-09 06:28:01
Coverage Exec Excl Total
Lines: 39.4% 13 7 40
Functions: 75.0% 3 0 4
Branches: 18.0% 11 6 67

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #include "CompilerError.h"
4
5 #include <util/CodeLoc.h>
6
7 namespace spice::compiler {
8
9 106 CompilerError::CompilerError(const CompilerErrorType &type, const std::string &message) {
10
1/2
✓ Branch 4 → 5 taken 106 times.
✗ Branch 4 → 22 not taken.
106 errorMessage = "[Error|Compiler]:\n";
11
4/8
✓ Branch 5 → 6 taken 106 times.
✗ Branch 5 → 19 not taken.
✓ Branch 6 → 7 taken 106 times.
✗ Branch 6 → 17 not taken.
✓ Branch 7 → 8 taken 106 times.
✗ Branch 7 → 15 not taken.
✓ Branch 8 → 9 taken 106 times.
✗ Branch 8 → 13 not taken.
106 errorMessage += getMessagePrefix(type) + ": " + message;
12 106 }
13
14 CompilerError::CompilerError(const CodeLoc &codeLoc, const CompilerErrorType &type, const std::string &message) {
15 errorMessage = "[Error|Compiler] " + codeLoc.toPrettyString() + ":\n";
16 errorMessage += getMessagePrefix(type) + ": " + message;
17 }
18
19 /**
20 * Get the message for this particular error instance
21 *
22 * @return Error message in form of a char array
23 */
24 106 const char *CompilerError::what() const noexcept { return errorMessage.c_str(); }
25
26 /**
27 * Get the prefix of the error message for a particular error
28 *
29 * @param errorType Type of the error
30 * @return Prefix string for the error type
31 */
32 106 std::string CompilerError::getMessagePrefix(CompilerErrorType errorType) {
33
3/15
✓ Branch 2 → 3 taken 104 times.
✓ Branch 2 → 8 taken 1 time.
✗ Branch 2 → 13 not taken.
✗ Branch 2 → 18 not taken.
✗ Branch 2 → 23 not taken.
✗ Branch 2 → 28 not taken.
✗ Branch 2 → 33 not taken.
✗ Branch 2 → 38 not taken.
✗ Branch 2 → 43 not taken.
✗ Branch 2 → 48 not taken.
✗ Branch 2 → 53 not taken.
✓ Branch 2 → 58 taken 1 time.
✗ Branch 2 → 63 not taken.
✗ Branch 2 → 68 not taken.
✗ Branch 2 → 73 not taken.
106 switch (errorType) {
34 104 case UNRESOLVED_SOFT_ERRORS:
35
1/2
✓ Branch 5 → 6 taken 104 times.
✗ Branch 5 → 75 not taken.
208 return "Unresolved soft errors";
36 1 case SOURCE_FILE_NOT_FOUND:
37
1/2
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 78 not taken.
2 return "Source file not found";
38 case CANT_OPEN_OUTPUT_FILE:
39 return "Could not open output file";
40 case WRONG_OUTPUT_TYPE:
41 return "Wrong type of output file";
42 case INTERNAL_ERROR:
43 return "Internal compiler error";
44 case IO_ERROR:
45 return "I/O Error";
46 case STD_NOT_FOUND:
47 return "Std lib not found";
48 case BOOTSTRAP_NOT_FOUND:
49 return "Bootstrap compiler not found";
50 case UNHANDLED_BRANCH: // LCOV_EXCL_LINE
51 return "Unhandled code branch"; // LCOV_EXCL_LINE
52 case TYPE_CHECKER_RUNS_EXCEEDED:
53 return "Type-checker runs exceeded";
54 case TARGET_NOT_AVAILABLE:
55 return "Selected target not available";
56 1 case OOM:
57
1/2
✓ Branch 60 → 61 taken 1 time.
✗ Branch 60 → 108 not taken.
2 return "An out of memory error occurred";
58 case INVALID_FUNCTION: // LCOV_EXCL_LINE
59 return "Invalid function"; // LCOV_EXCL_LINE
60 case INVALID_MODULE: // LCOV_EXCL_LINE
61 return "Invalid module"; // LCOV_EXCL_LINE
62 }
63 assert_fail("Unknown error"); // GCOV_EXCL_LINE
64 return "Unknown error"; // GCOV_EXCL_LINE
65 }
66
67 } // namespace spice::compiler
68