GCC Code Coverage Report


Directory: ../
File: src/util/CodeLoc.cpp
Date: 2025-02-05 01:09:36
Exec Total Coverage
Lines: 13 13 100.0%
Functions: 5 5 100.0%
Branches: 22 46 47.8%

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 0 (4→5) taken 1380667 times.
✗ Branch 1 (4→18) not taken.
✓ Branch 2 (5→6) taken 1380667 times.
✗ Branch 3 (5→16) not taken.
✓ Branch 4 (6→7) taken 1380667 times.
✗ Branch 5 (6→14) not taken.
1380667 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 2271 std::string CodeLoc::toPrettyString() const {
25
1/2
✓ Branch 0 (2→3) taken 2271 times.
✗ Branch 1 (2→61) not taken.
2271 const std::filesystem::path &rootSourceFilePath = sourceFile->getRootSourceFile()->filePath;
26
1/2
✓ Branch 0 (3→4) taken 2271 times.
✗ Branch 1 (3→61) not taken.
2271 std::filesystem::path sourceFilePath = relative(sourceFile->filePath, rootSourceFilePath);
27
3/4
✓ Branch 0 (4→5) taken 2271 times.
✗ Branch 1 (4→35) not taken.
✓ Branch 2 (7→8) taken 346 times.
✓ Branch 3 (7→9) taken 1925 times.
2271 if (sourceFilePath == ".")
28
1/2
✓ Branch 0 (8→9) taken 346 times.
✗ Branch 1 (8→59) not taken.
346 sourceFilePath /= sourceFile->fileName;
29
5/16
✗ Branch 0 (10→11) not taken.
✓ Branch 1 (10→14) taken 2271 times.
✗ Branch 2 (13→16) not taken.
✗ Branch 3 (13→36) not taken.
✓ Branch 4 (14→15) taken 2271 times.
✗ Branch 5 (14→36) not taken.
✓ Branch 6 (15→16) taken 2271 times.
✗ Branch 7 (15→36) not taken.
✓ Branch 8 (16→17) taken 2271 times.
✗ Branch 9 (16→18) not taken.
✗ Branch 10 (18→19) not taken.
✓ Branch 11 (18→21) taken 2271 times.
✗ Branch 12 (36→37) not taken.
✗ Branch 13 (36→38) not taken.
✗ Branch 14 (40→41) not taken.
✗ Branch 15 (40→43) not taken.
2271 const std::string prefix = sourceFilePath.empty() ? "" : sourceFilePath.generic_string() + ":";
30
3/6
✓ Branch 0 (23→24) taken 2271 times.
✗ Branch 1 (23→49) not taken.
✓ Branch 2 (24→25) taken 2271 times.
✗ Branch 3 (24→47) not taken.
✓ Branch 4 (25→26) taken 2271 times.
✗ Branch 5 (25→45) not taken.
4542 return prefix + std::to_string(line) + ":" + std::to_string(col);
31 2271 }
32
33 /**
34 * Returns the line number in a pretty form
35 *
36 * @return Pretty line number
37 */
38
1/2
✓ Branch 0 (3→4) taken 6028 times.
✗ Branch 1 (3→8) not taken.
6028 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 25717 std::string CodeLoc::toPrettyLineAndColumn() const { return toString(); }
46
47 99 bool operator==(const CodeLoc &a, const CodeLoc &b) {
48
4/6
✓ Branch 0 (3→4) taken 99 times.
✗ Branch 1 (3→7) not taken.
✓ Branch 2 (4→5) taken 10 times.
✓ Branch 3 (4→7) taken 89 times.
✓ Branch 4 (5→6) taken 10 times.
✗ Branch 5 (5→7) not taken.
99 return a.sourceFile->filePath == b.sourceFile->filePath && a.line == b.line && a.col == b.col;
49 }
50
51 } // namespace spice::compiler
52