GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 17 / 0 / 17
Functions: 100.0% 5 / 0 / 5
Branches: 62.5% 15 / 0 / 24

src/symboltablebuilder/Capture.cpp
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #include "Capture.h"
4
5 #include <symboltablebuilder/SymbolTableEntry.h>
6 #include <symboltablebuilder/TypeChain.h>
7
8 namespace spice::compiler {
9
10 24 Capture::Capture(SymbolTableEntry *entry) : capturedSymbol(entry) {
11 // Set the capture mode depending on the symbol type
12 // All types with guaranteed size <= 64 bit are captured by value, all others by reference.
13
3/4
✓ Branch 3 → 4 taken 24 times.
✗ Branch 3 → 8 not taken.
✓ Branch 4 → 5 taken 2 times.
✓ Branch 4 → 6 taken 22 times.
24 captureMode = entry->getQualType().isOneOf({TY_STRUCT, TY_INTERFACE}) ? BY_REFERENCE : BY_VALUE;
14 24 }
15
16 /**
17 * Retrieve the name of the capture
18 *
19 * @return Capture name or symbol name if no capture name was set
20 */
21 24 std::string Capture::getName() const { return capturedSymbol->name; }
22
23 /**
24 * Set the access type of this capture.
25 * Possible values are READ_ONLY and READ_WRITE
26 *
27 * @param captureAccessType Capture access type
28 */
29 7 void Capture::setAccessType(CaptureAccessType captureAccessType) {
30 7 accessType = captureAccessType;
31 // If we write to the captured symbol, we need to set the symbol to be a reference
32
1/2
✓ Branch 2 → 3 taken 7 times.
✗ Branch 2 → 4 not taken.
7 if (captureAccessType == READ_WRITE)
33 7 captureMode = BY_REFERENCE;
34 7 }
35
36 /**
37 * Retrieve the mode of this capture.
38 * Possible values are BY_VALUE and BY_REFERENCE
39 *
40 * @return Capture mode
41 */
42 99 CapturePassMode Capture::getMode() const { return captureMode; }
43
44 /**
45 * Stringify the current capture to a human-readable form. Used to dump whole symbol tables with their contents.
46 *
47 * Example:
48 * {
49 * "name": "testIdentifier",
50 * "accessType": "READ_ONLY",
51 * "mode": "BY_VALUE"
52 * }
53 *
54 * @return Capture as a JSON object
55 */
56 26 nlohmann::ordered_json Capture::toJSON() const {
57 26 nlohmann::json result;
58
2/4
✓ Branch 3 → 4 taken 26 times.
✗ Branch 3 → 28 not taken.
✓ Branch 4 → 5 taken 26 times.
✗ Branch 4 → 26 not taken.
26 result["name"] = capturedSymbol->name;
59
4/6
✓ Branch 7 → 8 taken 19 times.
✓ Branch 7 → 9 taken 7 times.
✓ Branch 10 → 11 taken 26 times.
✗ Branch 10 → 31 not taken.
✓ Branch 11 → 12 taken 26 times.
✗ Branch 11 → 29 not taken.
26 result["accessType"] = accessType == READ_ONLY ? "READ_ONLY" : "READ_WRITE";
60
4/6
✓ Branch 14 → 15 taken 17 times.
✓ Branch 14 → 16 taken 9 times.
✓ Branch 17 → 18 taken 26 times.
✗ Branch 17 → 35 not taken.
✓ Branch 18 → 19 taken 26 times.
✗ Branch 18 → 33 not taken.
26 result["mode"] = captureMode == BY_VALUE ? "BY_VALUE" : "BY_REFERENCE";
61
1/2
✓ Branch 21 → 22 taken 26 times.
✗ Branch 21 → 37 not taken.
52 return result;
62 26 }
63
64 } // namespace spice::compiler
65