| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2021-2025 ChilliBits. All rights reserved. | ||
| 2 | |||
| 3 | #include "Lifecycle.h" | ||
| 4 | |||
| 5 | namespace spice::compiler { | ||
| 6 | |||
| 7 | /** | ||
| 8 | * Add an event to the lifecycle | ||
| 9 | * | ||
| 10 | * @param event New lifecycle event | ||
| 11 | */ | ||
| 12 | 101595 | void Lifecycle::addEvent(const LifecycleEvent &event) { events.push_back(event); } | |
| 13 | |||
| 14 | /** | ||
| 15 | * Retrieve the current state of a symbol | ||
| 16 | * | ||
| 17 | * @return Current state | ||
| 18 | */ | ||
| 19 |
2/2✓ Branch 3 → 4 taken 55820 times.
✓ Branch 3 → 5 taken 219889 times.
|
275709 | LifecycleState Lifecycle::getCurrentState() const { return events.empty() ? DEAD : events.back().state; } |
| 20 | |||
| 21 | /** | ||
| 22 | * Retrieve the name of the current state of a symbol | ||
| 23 | * | ||
| 24 | * @return Current state name | ||
| 25 | */ | ||
| 26 | 168182 | const char *Lifecycle::getCurrentStateName() const { | |
| 27 |
3/4✓ Branch 3 → 4 taken 112213 times.
✓ Branch 3 → 5 taken 55553 times.
✓ Branch 3 → 6 taken 416 times.
✗ Branch 3 → 7 not taken.
|
168182 | switch (getCurrentState()) { |
| 28 | 112213 | case DECLARED: | |
| 29 | 112213 | return "declared"; | |
| 30 | 55553 | case INITIALIZED: | |
| 31 | 55553 | return "initialized"; | |
| 32 | 416 | case MOVED: | |
| 33 | 416 | return "moved"; | |
| 34 | ✗ | default: | |
| 35 | ✗ | return "dead"; | |
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Check if the symbol is dead | ||
| 41 | * | ||
| 42 | * @return Dead or not | ||
| 43 | */ | ||
| 44 | ✗ | bool Lifecycle::isDead() const { return getCurrentState() == DEAD; } | |
| 45 | |||
| 46 | /** | ||
| 47 | * Check if the symbol is declared | ||
| 48 | * | ||
| 49 | * @return Declared or not | ||
| 50 | */ | ||
| 51 | 43 | bool Lifecycle::isDeclared() const { return getCurrentState() == DECLARED; } | |
| 52 | |||
| 53 | /** | ||
| 54 | * Check if the symbol is initialized | ||
| 55 | * | ||
| 56 | * @return Initialized or not | ||
| 57 | */ | ||
| 58 | 5889 | bool Lifecycle::isInitialized() const { return getCurrentState() == INITIALIZED; } | |
| 59 | |||
| 60 | /** | ||
| 61 | * Check if the symbol was moved | ||
| 62 | * | ||
| 63 | * @return Moved or not | ||
| 64 | */ | ||
| 65 | ✗ | bool Lifecycle::wasMoved() const { return getCurrentState() == MOVED; } | |
| 66 | |||
| 67 | /** | ||
| 68 | * Check if the symbol is in an owning state | ||
| 69 | * | ||
| 70 | * @return Owning state or not | ||
| 71 | */ | ||
| 72 |
3/4✓ Branch 3 → 4 taken 43 times.
✗ Branch 3 → 6 not taken.
✓ Branch 5 → 6 taken 4 times.
✓ Branch 5 → 7 taken 39 times.
|
43 | bool Lifecycle::isInOwningState() const { return isDeclared() || isInitialized(); } |
| 73 | |||
| 74 | } // namespace spice::compiler | ||
| 75 |