GCC Code Coverage Report


Directory: ../
File: src/util/CodeLoc.cpp
Date: 2024-11-22 23:10:59
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-2024 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 3 taken 1316437 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1316437 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1316437 times.
✗ Branch 10 not taken.
1316437 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 1793 std::string CodeLoc::toPrettyString() const {
25
1/2
✓ Branch 1 taken 1793 times.
✗ Branch 2 not taken.
1793 const std::filesystem::path &rootSourceFilePath = sourceFile->getRootSourceFile()->filePath;
26
1/2
✓ Branch 1 taken 1793 times.
✗ Branch 2 not taken.
1793 std::filesystem::path sourceFilePath = relative(sourceFile->filePath, rootSourceFilePath);
27
3/4
✓ Branch 1 taken 1793 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 294 times.
✓ Branch 6 taken 1499 times.
1793 if (sourceFilePath == ".")
28
1/2
✓ Branch 1 taken 294 times.
✗ Branch 2 not taken.
294 sourceFilePath /= sourceFile->fileName;
29
5/16
✗ Branch 1 not taken.
✓ Branch 2 taken 1793 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 7 taken 1793 times.
✗ Branch 8 not taken.
✓ Branch 10 taken 1793 times.
✗ Branch 11 not taken.
✓ Branch 12 taken 1793 times.
✗ Branch 13 not taken.
✗ Branch 15 not taken.
✓ Branch 16 taken 1793 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
1793 const std::string prefix = sourceFilePath.empty() ? "" : sourceFilePath.generic_string() + ":";
30
3/6
✓ Branch 3 taken 1793 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 1793 times.
✗ Branch 7 not taken.
✓ Branch 9 taken 1793 times.
✗ Branch 10 not taken.
3586 return prefix + std::to_string(line) + ":" + std::to_string(col);
31 1793 }
32
33 /**
34 * Returns the line number in a pretty form
35 *
36 * @return Pretty line number
37 */
38
1/2
✓ Branch 2 taken 4942 times.
✗ Branch 3 not taken.
4942 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 20006 std::string CodeLoc::toPrettyLineAndColumn() const { return toString(); }
46
47 21 bool operator==(const CodeLoc &a, const CodeLoc &b) {
48
4/6
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 10 times.
✓ Branch 4 taken 11 times.
✓ Branch 5 taken 10 times.
✗ Branch 6 not taken.
21 return a.sourceFile->filePath == b.sourceFile->filePath && a.line == b.line && a.col == b.col;
49 }
50
51 } // namespace spice::compiler
52