Fixed crashes with empty context automaton

This commit is contained in:
Artur Meski
2022-03-20 13:22:36 +00:00
parent 98894fc6e1
commit 632286ec7f

View File

@@ -1,7 +1,7 @@
#include "ctx_aut.hh" #include "ctx_aut.hh"
#include "rs.hh"
#include "macro.hh" #include "macro.hh"
#include "rs.hh"
#include "stateconstr.hh" #include "stateconstr.hh"
CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys) CtxAut::CtxAut(Options *opts, RctSys *parent_rctsys)
@@ -75,6 +75,7 @@ void CtxAut::printAutomaton(void)
void CtxAut::showStates(void) void CtxAut::showStates(void)
{ {
if (states_ids.size() > 0) {
cout << "# Context Automaton States:" << endl; cout << "# Context Automaton States:" << endl;
cout << " = Init state: " << getStateName(init_state_id) << endl; cout << " = Init state: " << getStateName(init_state_id) << endl;
@@ -82,6 +83,7 @@ void CtxAut::showStates(void)
cout << " * " << s << endl; cout << " * " << s << endl;
} }
} }
}
void CtxAut::pushContextEntity(Entity entity_id) void CtxAut::pushContextEntity(Entity entity_id)
{ {
@@ -98,7 +100,8 @@ void CtxAut::saveCurrentContextSet(Process proc_id)
tmpEntities.clear(); tmpEntities.clear();
} }
void CtxAut::addTransition(std::string srcStateName, std::string dstStateName, StateConstr *stateConstr) void CtxAut::addTransition(std::string srcStateName, std::string dstStateName,
StateConstr *stateConstr)
{ {
VERB_L3("Saving transition"); VERB_L3("Saving transition");
@@ -115,12 +118,17 @@ void CtxAut::addTransition(std::string srcStateName, std::string dstStateName, S
void CtxAut::showTransitions(void) void CtxAut::showTransitions(void)
{ {
if (transitions.size() == 0) {
cout << "Empty context automaton" << endl;
return;
}
cout << "# Context Automaton Transitions:" << endl; cout << "# Context Automaton Transitions:" << endl;
for (const auto &t : transitions) { for (const auto &t : transitions) {
cout << " * [" << getStateName(t.src_state) << " -> " << getStateName( cout << " * [" << getStateName(t.src_state) << " -> "
t.dst_state) << getStateName(t.dst_state) << "]: { "
<< "]: { " << parent_rctsys->procEntitiesToStr(t.ctx) << "}"; << parent_rctsys->procEntitiesToStr(t.ctx) << "}";
if (t.state_constr != nullptr) { if (t.state_constr != nullptr) {
cout << " " << t.state_constr->toStr(); cout << " " << t.state_constr->toStr();
@@ -162,8 +170,8 @@ void CtxAut::makeProgressive(void)
State curr_st = t.src_state; State curr_st = t.src_state;
if (t.state_constr != nullptr) { if (t.state_constr != nullptr) {
constrs[curr_st] = new StateConstr( constrs[curr_st] =
STC_OR, constrs[curr_st], t.state_constr); new StateConstr(STC_OR, constrs[curr_st], t.state_constr);
} }
} }
@@ -174,13 +182,11 @@ void CtxAut::makeProgressive(void)
state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]); state_constr = new StateConstr(STC_NOT, constrs[getStateID(s)]);
addTransition(s, special_loc, state_constr); addTransition(s, special_loc, state_constr);
} }
} }
addTransition(special_loc, special_loc, nullptr); addTransition(special_loc, special_loc, nullptr);
made_progressive = true; made_progressive = true;
} }
/** EOF **/ /** EOF **/