GCC Code Coverage Report


Directory: ../
File: src/util/CompilerWarning.cpp
Date: 2026-01-06 18:16:09
Coverage Exec Excl Total
Lines: 95.9% 47 1 50
Functions: 100.0% 4 0 4
Branches: 59.0% 49 0 83

Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "CompilerWarning.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 warning occurred is known
11 *
12 * @param codeLoc Code location, where the warning occurred
13 * @param type Type of the warning
14 * @param message Warning message suffix
15 */
16 610 CompilerWarning::CompilerWarning(const CodeLoc &codeLoc, const CompilerWarningType type, const std::string &message) {
17
7/14
✓ Branch 3 → 4 taken 610 times.
✗ Branch 3 → 34 not taken.
✓ Branch 4 → 5 taken 610 times.
✗ Branch 4 → 29 not taken.
✓ Branch 5 → 6 taken 610 times.
✗ Branch 5 → 27 not taken.
✓ Branch 6 → 7 taken 610 times.
✗ Branch 6 → 25 not taken.
✓ Branch 7 → 8 taken 610 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 610 times.
✗ Branch 8 → 21 not taken.
✓ Branch 9 → 10 taken 610 times.
✗ Branch 9 → 19 not taken.
610 warningMessage = "[Warning] " + codeLoc.toPrettyString() + ": " + getMessagePrefix(type) + ": " + message;
18 610 }
19
20 /**
21 * Constructor: Used in case the exact code position where the warning occurred is not known
22 *
23 * @param type Type of the warning
24 * @param message Warning message suffix
25 */
26 1 CompilerWarning::CompilerWarning(CompilerWarningType type, const std::string &message) {
27
4/8
✓ Branch 3 → 4 taken 1 time.
✗ Branch 3 → 19 not taken.
✓ Branch 4 → 5 taken 1 time.
✗ Branch 4 → 17 not taken.
✓ Branch 5 → 6 taken 1 time.
✗ Branch 5 → 15 not taken.
✓ Branch 6 → 7 taken 1 time.
✗ Branch 6 → 13 not taken.
1 warningMessage = "[Warning] " + getMessagePrefix(type) + ": " + message;
28 1 }
29
30 /**
31 * Print the compiler warning to the standard error output
32 */
33 178 void CompilerWarning::print() const { std::cout << "\033[33m" << warningMessage << "\033[0m\n"; }
34
35 /**
36 * Get the prefix of the warning message for a particular error
37 *
38 * @param warningType Type of the warning
39 * @return Prefix string for the warning type
40 */
41 611 std::string CompilerWarning::getMessagePrefix(CompilerWarningType warningType) {
42
19/21
✓ Branch 2 → 3 taken 11 times.
✓ Branch 2 → 8 taken 1 time.
✓ Branch 2 → 13 taken 19 times.
✓ Branch 2 → 18 taken 1 time.
✓ Branch 2 → 23 taken 1 time.
✓ Branch 2 → 28 taken 2 times.
✓ Branch 2 → 33 taken 5 times.
✓ Branch 2 → 38 taken 27 times.
✓ Branch 2 → 43 taken 1 time.
✓ Branch 2 → 48 taken 61 times.
✓ Branch 2 → 53 taken 192 times.
✓ Branch 2 → 58 taken 3 times.
✓ Branch 2 → 63 taken 2 times.
✓ Branch 2 → 68 taken 275 times.
✓ Branch 2 → 73 taken 1 time.
✓ Branch 2 → 78 taken 2 times.
✓ Branch 2 → 83 taken 1 time.
✓ Branch 2 → 88 taken 5 times.
✗ Branch 2 → 93 not taken.
✓ Branch 2 → 98 taken 1 time.
✗ Branch 2 → 103 not taken.
611 switch (warningType) {
43 11 case UNUSED_FUNCTION:
44
1/2
✓ Branch 5 → 6 taken 11 times.
✗ Branch 5 → 105 not taken.
22 return "Unused function";
45 1 case UNUSED_PROCEDURE:
46
1/2
✓ Branch 10 → 11 taken 1 time.
✗ Branch 10 → 108 not taken.
2 return "Unused procedure";
47 19 case UNUSED_METHOD:
48
1/2
✓ Branch 15 → 16 taken 19 times.
✗ Branch 15 → 111 not taken.
38 return "Unused method";
49 1 case UNUSED_STRUCT:
50
1/2
✓ Branch 20 → 21 taken 1 time.
✗ Branch 20 → 114 not taken.
2 return "Unused struct";
51 1 case UNUSED_INTERFACE:
52
1/2
✓ Branch 25 → 26 taken 1 time.
✗ Branch 25 → 117 not taken.
2 return "Unused interface";
53 2 case UNUSED_IMPORT:
54
1/2
✓ Branch 30 → 31 taken 2 times.
✗ Branch 30 → 120 not taken.
4 return "Unused import";
55 5 case UNUSED_FIELD:
56
1/2
✓ Branch 35 → 36 taken 5 times.
✗ Branch 35 → 123 not taken.
10 return "Unused field";
57 27 case UNUSED_ENUM_ITEM:
58
1/2
✓ Branch 40 → 41 taken 27 times.
✗ Branch 40 → 126 not taken.
54 return "Unused enum item";
59 1 case UNUSED_ALIAS:
60
1/2
✓ Branch 45 → 46 taken 1 time.
✗ Branch 45 → 129 not taken.
2 return "Unused type alias";
61 61 case UNUSED_VARIABLE:
62
1/2
✓ Branch 50 → 51 taken 61 times.
✗ Branch 50 → 132 not taken.
122 return "Unused variable";
63 192 case UNUSED_RETURN_VALUE:
64
1/2
✓ Branch 55 → 56 taken 192 times.
✗ Branch 55 → 135 not taken.
384 return "Unused return value";
65 3 case UNREACHABLE_CODE:
66
1/2
✓ Branch 60 → 61 taken 3 times.
✗ Branch 60 → 138 not taken.
6 return "Unreachable code detected";
67 2 case SHADOWED_VARIABLE:
68
1/2
✓ Branch 65 → 66 taken 2 times.
✗ Branch 65 → 141 not taken.
4 return "Shadowed variable";
69 275 case IDENTITY_CAST:
70
1/2
✓ Branch 70 → 71 taken 275 times.
✗ Branch 70 → 144 not taken.
550 return "Identity cast";
71 1 case SINGLE_GENERIC_TYPE_CONDITION:
72
1/2
✓ Branch 75 → 76 taken 1 time.
✗ Branch 75 → 147 not taken.
2 return "Only one type condition";
73 2 case INEFFECTIVE_GENERIC_TYPE_CONDITION:
74
1/2
✓ Branch 80 → 81 taken 2 times.
✗ Branch 80 → 150 not taken.
4 return "Ineffective type condition";
75 1 case BOOL_ASSIGN_AS_CONDITION:
76
1/2
✓ Branch 85 → 86 taken 1 time.
✗ Branch 85 → 153 not taken.
2 return "Bool assignment as condition";
77 5 case ASYNC_LAMBDA_CAPTURE_RULE_VIOLATION:
78
1/2
✓ Branch 90 → 91 taken 5 times.
✗ Branch 90 → 156 not taken.
10 return "Lambda violates async lambda capture rules";
79 case UNINSTALL_FAILED:
80 return "Uninstall failed";
81 1 case VERIFIER_DISABLED:
82
1/2
✓ Branch 100 → 101 taken 1 time.
✗ Branch 100 → 162 not taken.
2 return "Verifier disabled";
83 }
84 assert_fail("Unknown warning"); // GCOV_EXCL_LINE
85 return "Unknown warning"; // GCOV_EXCL_LINE
86 }
87
88 } // namespace spice::compiler
89