| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "ParserError.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 | 8 | ParserError::ParserError(const CodeLoc &codeLoc, const ParserErrorType &type, const std::string &message) { | |
| 17 |
7/14✓ Branch 4 → 5 taken 8 times.
✗ Branch 4 → 35 not taken.
✓ Branch 5 → 6 taken 8 times.
✗ Branch 5 → 30 not taken.
✓ Branch 6 → 7 taken 8 times.
✗ Branch 6 → 28 not taken.
✓ Branch 7 → 8 taken 8 times.
✗ Branch 7 → 26 not taken.
✓ Branch 8 → 9 taken 8 times.
✗ Branch 8 → 24 not taken.
✓ Branch 9 → 10 taken 8 times.
✗ Branch 9 → 22 not taken.
✓ Branch 10 → 11 taken 8 times.
✗ Branch 10 → 20 not taken.
|
8 | errorMessage = "[Error|Parser] " + codeLoc.toPrettyString() + ": " + getMessagePrefix(type) + ": " + message; |
| 18 | 8 | } | |
| 19 | |||
| 20 | /** | ||
| 21 | * Get the message for this particular error instance | ||
| 22 | * | ||
| 23 | * @return Error message in form of a char array | ||
| 24 | */ | ||
| 25 | 8 | const char *ParserError::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 | 8 | std::string ParserError::getMessagePrefix(ParserErrorType errorType) { | |
| 34 |
7/8✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 8 taken 1 time.
✓ Branch 2 → 13 taken 1 time.
✓ Branch 2 → 18 taken 1 time.
✓ Branch 2 → 23 taken 1 time.
✓ Branch 2 → 28 taken 1 time.
✓ Branch 2 → 33 taken 1 time.
✗ Branch 2 → 38 not taken.
|
8 | switch (errorType) { |
| 35 | 2 | case PARSING_FAILED: | |
| 36 |
1/2✓ Branch 5 → 6 taken 2 times.
✗ Branch 5 → 40 not taken.
|
4 | return "Parsing failed"; |
| 37 | 1 | case NUMBER_OUT_OF_RANGE: | |
| 38 |
1/2✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 43 not taken.
|
2 | return "Number is out of range"; |
| 39 | 1 | case INVALID_QUALIFIER_COMBINATION: | |
| 40 |
1/2✓ Branch 15 → 16 taken 1 time.
✗ Branch 15 → 46 not taken.
|
2 | return "Invalid qualifier combination"; |
| 41 | 1 | case INVALID_CHAR_LITERAL: | |
| 42 |
1/2✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 49 not taken.
|
2 | return "Invalid char literal"; |
| 43 | 1 | case INVALID_ATTR_VALUE_TYPE: | |
| 44 |
1/2✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 52 not taken.
|
2 | return "Invalid attribute value type"; |
| 45 | 1 | case RESERVED_KEYWORD: | |
| 46 |
1/2✓ Branch 30 → 31 taken 1 time.
✗ Branch 30 → 55 not taken.
|
2 | return "Usage of reserved keyword"; |
| 47 | 1 | case RESERVED_TYPENAME: | |
| 48 |
1/2✓ Branch 35 → 36 taken 1 time.
✗ Branch 35 → 58 not taken.
|
2 | return "Usage of reserved typename"; |
| 49 | } | ||
| 50 | − | assert_fail("Unknown error"); // GCOV_EXCL_LINE | |
| 51 | return "Unknown error"; // GCOV_EXCL_LINE | ||
| 52 | } | ||
| 53 | |||
| 54 | } // namespace spice::compiler | ||
| 55 |