Skip to content

Commit 4c25fb4

Browse files
authored
Merge pull request #50 from lf-lang/assert-fix
Fix validate method and fix incorrect phase checks
2 parents b607f1f + e356478 commit 4c25fb4

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

include/reactor-cpp/assert.hh

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,19 @@
99
#ifndef REACTOR_CPP_ASSERT_HH
1010
#define REACTOR_CPP_ASSERT_HH
1111

12+
#include "reactor-cpp/config.hh"
13+
#include "reactor-cpp/fwd.hh"
14+
15+
#include <cassert>
16+
#include <sstream>
17+
#include <stdexcept>
18+
#include <string>
19+
20+
#ifdef __linux__
21+
#include <execinfo.h>
22+
#include <unistd.h>
23+
#endif
24+
1225
#ifdef REACTOR_CPP_VALIDATE
1326
constexpr bool runtime_validation = true;
1427
#else
@@ -21,18 +34,6 @@ constexpr bool runtime_assertion = false;
2134
constexpr bool runtime_assertion = true;
2235
#endif
2336

24-
#include "fwd.hh"
25-
26-
#include <cassert>
27-
#include <sstream>
28-
#include <stdexcept>
29-
#include <string>
30-
31-
#ifdef __linux__
32-
#include <execinfo.h>
33-
#include <unistd.h>
34-
#endif
35-
3637
// NOLINTNEXTLINE(cppcoreguidelines-macro-usage)
3738
#define reactor_assert(x) assert(x)
3839

lib/environment.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ void Environment::register_reactor(Reactor* reactor) {
5555

5656
void Environment::register_input_action(BaseAction* action) {
5757
reactor_assert(action != nullptr);
58-
validate(this->phase() == Phase::Construction, "Input actions may only be registered during construction phase!");
58+
validate(this->phase() == Phase::Construction || this->phase() == Phase::Assembly,
59+
"Input actions may only be registered during construction or assembly phase!");
5960
[[maybe_unused]] bool result = input_actions_.insert(action).second;
6061
reactor_assert(result);
6162
run_forever_ = true;

lib/reactor.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,16 @@ ReactorElement::ReactorElement(const std::string& name, ReactorElement::Type typ
6565
, environment_(environment) {
6666
reactor_assert(environment != nullptr);
6767
validate(type == Type::Reactor || type == Type::Action, "Only reactors and actions can be owned by the environment!");
68-
validate(this->environment_->phase() == Phase::Construction,
69-
"Reactor elements can only be created during construction phase!");
7068

7169
switch (type) {
7270
case Type::Action:
71+
validate(this->environment_->phase() == Phase::Construction || this->environment_->phase() == Phase::Assembly,
72+
"Actions can only be created during construction or assembly phase!");
7373
Statistics::increment_actions();
7474
break;
7575
case Type::Reactor:
76+
validate(this->environment_->phase() == Phase::Construction,
77+
"Reactors can only be created during construction phase!");
7678
Statistics::increment_reactor_instances();
7779
break;
7880
default:

0 commit comments

Comments
 (0)