// Fixture for tool/cpp_front.py: each case is a positive or negative control // for a rule run on the C++ state model (see test/cpp_front_test.dart). namespace fx { // Ghost is compared against but never produced: rendered-not-emitted. enum class Phase { Idle, Starting, Running, Failed, Ghost }; // Produced, never compared or switched on: emitted-not-rendered. enum class Unread { A, B }; // Y is compared against and produced only through a cast from an int, so the // rule must suppress itself rather than call the branch dead. enum class Casted { X, Y }; void mayThrow(); class Engine { public: // Negative: the catch resolves the busy state. void startGuarded() { phase_ = Phase::Starting; try { mayThrow(); phase_ = Phase::Running; } catch (...) { phase_ = Phase::Failed; } } // Positive: busy state set, then a top-level try whose catch swallows the // failure, so Starting can outlive it (loading-not-reset). void startSwallowed() { phase_ = Phase::Starting; try { mayThrow(); phase_ = Phase::Running; } catch (...) { } } // Negative: a nested try is a local fallback, not the method's failure path. void startNested() { phase_ = Phase::Starting; if (ready_) { try { mayThrow(); } catch (...) { } } phase_ = Phase::Running; } bool ghost() const { return phase_ == Phase::Ghost; } bool idle() const { switch (phase_) { case Phase::Idle: return true; case Phase::Starting: case Phase::Running: case Phase::Failed: return false; default: return false; } } void setUnread() { unread_ = Unread::A; unread_ = Unread::B; } void load(int n) { casted_ = static_cast(n); } bool isY() const { return casted_ == Casted::Y; } private: bool ready_ = false; Phase phase_ = Phase::Idle; Unread unread_ = Unread::A; Casted casted_ = Casted::X; }; // Negative: `ev.stage` is a field of a local event object handed to a callback, // not state Reporter holds, so its try cannot leave Reporter stuck. struct Event { Phase stage; }; void notify(const Event&); class Reporter { public: void run() { Event ev; ev.stage = Phase::Starting; notify(ev); try { mayThrow(); } catch (...) { } } }; } // namespace fx