GCC Code Coverage Report


Directory: ../
File: src/exception/LexerError.cpp
Date: 2025-11-03 22:22:45
Coverage Exec Excl Total
Lines: 100.0% 8 1 9
Functions: 100.0% 3 0 3
Branches: 50.0% 9 0 18

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #include "LexerError.h"
4
5 #include <util/CodeLoc.h>
6
7 namespace spice::compiler {
8
9 /**
10 * Constructor: Used in case that the exact code position where the error occurred is known
11 *
12 * @param codeLoc Code location where the error occurred
13 * @param type Type of the error
14 * @param message Error message suffix
15 */
16 1 LexerError::LexerError(const CodeLoc &codeLoc, const LexerErrorType &type, const std::string &message) {
17
7/14
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 35 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 28 not taken.
✓ Branch 7 → 8 taken 1 time.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 22 not taken.
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 20 not taken.
1 errorMessage = "[Error|Lexer] " + codeLoc.toPrettyString() + ": " + getMessagePrefix(type) + ": " + message;
18 1 }
19
20 /**
21 * Get the message for this particular error instance
22 *
23 * @return Error message in form of a char array
24 */
25 1 const char *LexerError::what() const noexcept { return errorMessage.c_str(); }
26
27 /**
28 * Get the prefix of the error message for a particular error
29 *
30 * @param errorType Type of the error
31 * @return Prefix string for the error type
32 */
33 1 std::string LexerError::getMessagePrefix(LexerErrorType errorType) {
34
1/2
✓ Branch 2 → 3 taken 1 time.
✗ Branch 2 → 8 not taken.
1 switch (errorType) {
35 1 case TOKENIZING_FAILED:
36
1/2
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 10 not taken.
2 return "Tokenizing failed";
37 }
38 assert_fail("Unknown error"); // GCOV_EXCL_LINE
39 return "Unknown error"; // GCOV_EXCL_LINE
40 }
41
42 } // namespace spice::compiler
43