GCC Code Coverage Report


Directory: ../
File: src/symboltablebuilder/Capture.cpp
Date: 2024-11-22 23:10:59
Exec Total Coverage
Lines: 17 17 100.0%
Functions: 5 5 100.0%
Branches: 14 24 58.3%

Line Branch Exec Source
1 // Copyright (c) 2021-2024 ChilliBits. All rights reserved.
2
3 #include "Capture.h"
4
5 #include <symboltablebuilder/TypeChain.h>
6
7 namespace spice::compiler {
8
9 22 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
2/4
✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 22 times.
22 captureMode = entry->getQualType().isOneOf({TY_STRUCT, TY_INTERFACE}) ? BY_REFERENCE : BY_VALUE;
13 22 }
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 22 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 taken 7 times.
✗ Branch 1 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 91 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 24 nlohmann::ordered_json Capture::toJSON() const {
56 24 nlohmann::json result;
57
2/4
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 24 times.
✗ Branch 5 not taken.
24 result["name"] = capturedSymbol->name;
58
4/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
24 result["accessType"] = accessType == READ_ONLY ? "READ_ONLY" : "READ_WRITE";
59
4/6
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 7 times.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 24 times.
✗ Branch 7 not taken.
24 result["mode"] = captureMode == BY_VALUE ? "BY_VALUE" : "BY_REFERENCE";
60
1/2
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
48 return result;
61 24 }
62
63 } // namespace spice::compiler
64