GCC Code Coverage Report


Directory: ../
File: src/util/CodeLoc.cpp
Date: 2025-10-23 00:48:11
Coverage Exec Excl Total
Lines: 100.0% 13 0 13
Functions: 100.0% 5 0 5
Branches: 47.8% 22 0 46

Line Branch Exec Source
1 // Copyright (c) 2021-2025 ChilliBits. All rights reserved.
2
3 #include "CodeLoc.h"
4
5 #include <filesystem>
6 #include <string>
7
8 #include <SourceFile.h>
9
10 namespace spice::compiler {
11
12 /**
13 * Returns the code location as a string for using it as a map key or similar
14 *
15 * @return Code location string
16 */
17
3/6
✓ Branch 4 → 5 taken 1749289 times.
✗ Branch 4 → 18 not taken.
✓ Branch 5 → 6 taken 1749289 times.
✗ Branch 5 → 16 not taken.
✓ Branch 6 → 7 taken 1749289 times.
✗ Branch 6 → 14 not taken.
1749289 std::string CodeLoc::toString() const { return "L" + std::to_string(line) + "C" + std::to_string(col); }
18
19 /**
20 * Returns the code location in a pretty form
21 *
22 * @return Pretty code location
23 */
24 1494 std::string CodeLoc::toPrettyString() const {
25
1/2
✓ Branch 2 → 3 taken 1494 times.
✗ Branch 2 → 61 not taken.
1494 const std::filesystem::path &rootSourceFilePath = sourceFile->getRootSourceFile()->filePath;
26
1/2
✓ Branch 3 → 4 taken 1494 times.
✗ Branch 3 → 61 not taken.
1494 std::filesystem::path sourceFilePath = relative(sourceFile->filePath, rootSourceFilePath);
27
3/4
✓ Branch 4 → 5 taken 1494 times.
✗ Branch 4 → 35 not taken.
✓ Branch 7 → 8 taken 357 times.
✓ Branch 7 → 9 taken 1137 times.
1494 if (sourceFilePath == ".")
28
1/2
✓ Branch 8 → 9 taken 357 times.
✗ Branch 8 → 59 not taken.
357 sourceFilePath /= sourceFile->fileName;
29
5/16
✗ Branch 10 → 11 not taken.
✓ Branch 10 → 14 taken 1494 times.
✗ Branch 13 → 16 not taken.
✗ Branch 13 → 36 not taken.
✓ Branch 14 → 15 taken 1494 times.
✗ Branch 14 → 36 not taken.
✓ Branch 15 → 16 taken 1494 times.
✗ Branch 15 → 36 not taken.
✓ Branch 16 → 17 taken 1494 times.
✗ Branch 16 → 18 not taken.
✗ Branch 18 → 19 not taken.
✓ Branch 18 → 21 taken 1494 times.
✗ Branch 36 → 37 not taken.
✗ Branch 36 → 38 not taken.
✗ Branch 40 → 41 not taken.
✗ Branch 40 → 43 not taken.
1494 const std::string prefix = sourceFilePath.empty() ? "" : sourceFilePath.generic_string() + ":";
30
3/6
✓ Branch 23 → 24 taken 1494 times.
✗ Branch 23 → 49 not taken.
✓ Branch 24 → 25 taken 1494 times.
✗ Branch 24 → 47 not taken.
✓ Branch 25 → 26 taken 1494 times.
✗ Branch 25 → 45 not taken.
2988 return prefix + std::to_string(line) + ":" + std::to_string(col);
31 1494 }
32
33 /**
34 * Returns the line number in a pretty form
35 *
36 * @return Pretty line number
37 */
38
1/2
✓ Branch 3 → 4 taken 6780 times.
✗ Branch 3 → 8 not taken.
6780 std::string CodeLoc::toPrettyLine() const { return "L" + std::to_string(line); }
39
40 /**
41 * Returns the line and column numbers in a pretty form
42 *
43 * @return Pretty line and column numbers
44 */
45 31821 std::string CodeLoc::toPrettyLineAndColumn() const { return toString(); }
46
47 98 bool operator==(const CodeLoc &a, const CodeLoc &b) {
48
4/6
✓ Branch 3 → 4 taken 98 times.
✗ Branch 3 → 7 not taken.
✓ Branch 4 → 5 taken 9 times.
✓ Branch 4 → 7 taken 89 times.
✓ Branch 5 → 6 taken 9 times.
✗ Branch 5 → 7 not taken.
98 return a.sourceFile->filePath == b.sourceFile->filePath && a.line == b.line && a.col == b.col;
49 }
50
51 } // namespace spice::compiler
52