GCC Code Coverage Report


Directory: ../
File: src/exception/CompilerError.cpp
Date: 2024-12-24 01:17:15
Exec Total Coverage
Lines: 13 33 39.4%
Functions: 3 4 75.0%
Branches: 11 61 18.0%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 ChilliBits. All rights reserved.
2
3 #include "CompilerError.h"
4
5 #include <util/CodeLoc.h>
6
7 namespace spice::compiler {
8
9 103 CompilerError::CompilerError(const CompilerErrorType &type, const std::string &message) {
10
1/2
✓ Branch 1 taken 103 times.
✗ Branch 2 not taken.
103 errorMessage = "[Error|Compiler]:\n";
11
4/8
✓ Branch 1 taken 103 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 103 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 103 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 103 times.
✗ Branch 11 not taken.
103 errorMessage += getMessagePrefix(type) + ": " + message;
12 103 }
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 103 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 103 std::string CompilerError::getMessagePrefix(CompilerErrorType errorType) {
33
3/15
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
103 switch (errorType) {
34 101 case UNRESOLVED_SOFT_ERRORS:
35
1/2
✓ Branch 1 taken 101 times.
✗ Branch 2 not taken.
202 return "Unresolved soft errors";
36 1 case SOURCE_FILE_NOT_FOUND:
37
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 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 1 taken 1 times.
✗ Branch 2 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 return "Unknown error"; // GCOV_EXCL_LINE
64 }
65
66 } // namespace spice::compiler
67