GCC Code Coverage Report


Directory: ../
File: src/util/CompilerWarning.cpp
Date: 2025-02-05 01:09:36
Exec Total Coverage
Lines: 40 47 85.1%
Functions: 3 4 75.0%
Branches: 41 80 51.2%

Line Branch Exec Source
1 // Copyright (c) 2021-2025 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 1498 CompilerWarning::CompilerWarning(const CodeLoc &codeLoc, const CompilerWarningType type, const std::string &message) {
17
7/14
✓ Branch 0 (3→4) taken 1498 times.
✗ Branch 1 (3→34) not taken.
✓ Branch 2 (4→5) taken 1498 times.
✗ Branch 3 (4→29) not taken.
✓ Branch 4 (5→6) taken 1498 times.
✗ Branch 5 (5→27) not taken.
✓ Branch 6 (6→7) taken 1498 times.
✗ Branch 7 (6→25) not taken.
✓ Branch 8 (7→8) taken 1498 times.
✗ Branch 9 (7→23) not taken.
✓ Branch 10 (8→9) taken 1498 times.
✗ Branch 11 (8→21) not taken.
✓ Branch 12 (9→10) taken 1498 times.
✗ Branch 13 (9→19) not taken.
1498 warningMessage = "[Warning] " + codeLoc.toPrettyString() + ": " + getMessagePrefix(type) + ": " + message;
18 1498 }
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 CompilerWarning::CompilerWarning(CompilerWarningType type, const std::string &message) {
27 warningMessage = "[Warning] " + getMessagePrefix(type) + ": " + message;
28 }
29
30 /**
31 * Print the compiler warning to the standard error output
32 */
33 209 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 1498 std::string CompilerWarning::getMessagePrefix(CompilerWarningType warningType) {
42
17/20
✓ Branch 0 (2→3) taken 11 times.
✓ Branch 1 (2→8) taken 2 times.
✓ Branch 2 (2→13) taken 19 times.
✓ Branch 3 (2→18) taken 2 times.
✓ Branch 4 (2→23) taken 1 times.
✓ Branch 5 (2→28) taken 4 times.
✓ Branch 6 (2→33) taken 11 times.
✓ Branch 7 (2→38) taken 37 times.
✓ Branch 8 (2→43) taken 1 times.
✓ Branch 9 (2→48) taken 58 times.
✓ Branch 10 (2→53) taken 118 times.
✓ Branch 11 (2→58) taken 7 times.
✓ Branch 12 (2→63) taken 30 times.
✓ Branch 13 (2→68) taken 1190 times.
✓ Branch 14 (2→73) taken 1 times.
✓ Branch 15 (2→78) taken 1 times.
✓ Branch 16 (2→83) taken 5 times.
✗ Branch 17 (2→88) not taken.
✗ Branch 18 (2→93) not taken.
✗ Branch 19 (2→98) not taken.
1498 switch (warningType) {
43 11 case UNUSED_FUNCTION:
44
1/2
✓ Branch 0 (5→6) taken 11 times.
✗ Branch 1 (5→104) not taken.
22 return "Unused function";
45 2 case UNUSED_PROCEDURE:
46
1/2
✓ Branch 0 (10→11) taken 2 times.
✗ Branch 1 (10→107) not taken.
4 return "Unused procedure";
47 19 case UNUSED_METHOD:
48
1/2
✓ Branch 0 (15→16) taken 19 times.
✗ Branch 1 (15→110) not taken.
38 return "Unused method";
49 2 case UNUSED_STRUCT:
50
1/2
✓ Branch 0 (20→21) taken 2 times.
✗ Branch 1 (20→113) not taken.
4 return "Unused struct";
51 1 case UNUSED_INTERFACE:
52
1/2
✓ Branch 0 (25→26) taken 1 times.
✗ Branch 1 (25→116) not taken.
2 return "Unused interface";
53 4 case UNUSED_IMPORT:
54
1/2
✓ Branch 0 (30→31) taken 4 times.
✗ Branch 1 (30→119) not taken.
8 return "Unused import";
55 11 case UNUSED_FIELD:
56
1/2
✓ Branch 0 (35→36) taken 11 times.
✗ Branch 1 (35→122) not taken.
22 return "Unused field";
57 37 case UNUSED_ENUM_ITEM:
58
1/2
✓ Branch 0 (40→41) taken 37 times.
✗ Branch 1 (40→125) not taken.
74 return "Unused enum item";
59 1 case UNUSED_ALIAS:
60
1/2
✓ Branch 0 (45→46) taken 1 times.
✗ Branch 1 (45→128) not taken.
2 return "Unused type alias";
61 58 case UNUSED_VARIABLE:
62
1/2
✓ Branch 0 (50→51) taken 58 times.
✗ Branch 1 (50→131) not taken.
116 return "Unused variable";
63 118 case UNUSED_RETURN_VALUE:
64
1/2
✓ Branch 0 (55→56) taken 118 times.
✗ Branch 1 (55→134) not taken.
236 return "Unused return value";
65 7 case UNREACHABLE_CODE:
66
1/2
✓ Branch 0 (60→61) taken 7 times.
✗ Branch 1 (60→137) not taken.
14 return "Unreachable code detected";
67 30 case SHADOWED_VARIABLE:
68
1/2
✓ Branch 0 (65→66) taken 30 times.
✗ Branch 1 (65→140) not taken.
60 return "Shadowed variable";
69 1190 case IDENTITY_CAST:
70
1/2
✓ Branch 0 (70→71) taken 1190 times.
✗ Branch 1 (70→143) not taken.
2380 return "Identity cast";
71 1 case SINGLE_GENERIC_TYPE_CONDITION:
72
1/2
✓ Branch 0 (75→76) taken 1 times.
✗ Branch 1 (75→146) not taken.
2 return "Only one type condition";
73 1 case BOOL_ASSIGN_AS_CONDITION:
74
1/2
✓ Branch 0 (80→81) taken 1 times.
✗ Branch 1 (80→149) not taken.
2 return "Bool assignment as condition";
75 5 case ASYNC_LAMBDA_CAPTURE_RULE_VIOLATION:
76
1/2
✓ Branch 0 (85→86) taken 5 times.
✗ Branch 1 (85→152) not taken.
10 return "Lambda violates async lambda capture rules";
77 case UNINSTALL_FAILED:
78 return "Uninstall failed";
79 case VERIFIER_DISABLED:
80 return "Verifier disabled";
81 }
82 return "Unknown warning"; // GCOV_EXCL_LINE
83 }
84
85 } // namespace spice::compiler
86