GCC Code Coverage Report


Directory: ../
File: src/util/DeferredLogic.h
Date: 2026-01-06 18:16:09
Coverage Exec Excl Total
Lines: 100.0% 10 0 10
Functions: 100.0% 3 0 3
Branches: 100.0% 4 0 4

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 19071 explicit DeferredLogic(std::function<void()> deferredFunc, const bool triggerOnDestruct = true)
16 19071 : deferredFunc(std::move(deferredFunc)), triggerOnDestruct(triggerOnDestruct) {}
17
18 // Destructor
19 19289 ~DeferredLogic() {
20
4/4
✓ Branch 2 → 3 taken 18675 times.
✓ Branch 2 → 5 taken 614 times.
✓ Branch 3 → 4 taken 9591 times.
✓ Branch 3 → 5 taken 9084 times.
19289 if (triggerOnDestruct && !alreadyExecuted)
21 9591 deferredFunc();
22 19289 }
23
24 // Public methods
25 9480 void execute() {
26 9480 deferredFunc();
27 9480 alreadyExecuted = true;
28 9480 }
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