GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/Capture.cpp
Date: 2025-02-05 01:09:36
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 5 5 100.0%
Branches: 15 24 62.5%

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