GCC Code Coverage Report


Directory: ../
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 100.0% 10 / 0 / 10
Functions: 100.0% 3 / 0 / 3
Branches: 100.0% 4 / 0 / 4

src/util/DeferredLogic.h
Line Branch Exec Source
1 // Copyright (c) 2021-2026 ChilliBits. All rights reserved.
2
3 #pragma once
4
5 #include <functional>
6 #include <utility>
7
8 namespace spice::compiler {
9
10 /**
11 * RAII helper that can run a lambda at the end of the scope
12 **/
13 struct DeferredLogic {
14 // Constructors
15 80652 explicit DeferredLogic(std::function<void()> deferredFunc, const bool triggerOnDestruct = true)
16 161304 : deferredFunc(std::move(deferredFunc)), triggerOnDestruct(triggerOnDestruct) {}
17
18 // Destructor
19 82835 ~DeferredLogic() {
20
4/4
✓ Branch 2 → 3 taken 78375 times.
✓ Branch 2 → 5 taken 4460 times.
✓ Branch 3 → 4 taken 35326 times.
✓ Branch 3 → 5 taken 43049 times.
82835 if (triggerOnDestruct && !alreadyExecuted)
21 35326 deferredFunc();
22 82835 }
23
24 // Public methods
25 45326 void execute() {
26 45326 deferredFunc();
27 45326 alreadyExecuted = true;
28 45326 }
29
30 private:
31 // Private members
32 std::function<void()> deferredFunc;
33 bool triggerOnDestruct;
34 bool alreadyExecuted = false;
35 };
36
37 } // namespace spice::compiler
38