hoa,dot: propagate state names

* src/hoaparse/hoaparse.yy: Store state names.
* src/tgbaalgos/dotty.cc, src/tgbaalgos/hoa.cc: Output them.
* src/tgbatest/readsave.test: Test this.
* src/tgbatest/hoaparse.test: Update.
This commit is contained in:
Alexandre Duret-Lutz 2015-01-23 18:34:57 +01:00
parent ae50155297
commit 9add895ba7
5 changed files with 50 additions and 23 deletions

View file

@ -81,6 +81,7 @@
spot::acc_cond::mark_t acc_state; spot::acc_cond::mark_t acc_state;
spot::acc_cond::mark_t neg_acc_sets = 0U; spot::acc_cond::mark_t neg_acc_sets = 0U;
spot::acc_cond::mark_t pos_acc_sets = 0U; spot::acc_cond::mark_t pos_acc_sets = 0U;
std::vector<std::string>* state_names = nullptr;
unsigned cur_state; unsigned cur_state;
int states = -1; int states = -1;
int ap_count = -1; int ap_count = -1;
@ -176,6 +177,7 @@
%type <num> checked-state-num state-num acc-set %type <num> checked-state-num state-num acc-set
%type <b> label-expr %type <b> label-expr
%type <mark> acc-sig acc-sets trans-acc_opt state-acc_opt %type <mark> acc-sig acc-sets trans-acc_opt state-acc_opt
%type <str> string_opt
/**** NEVERCLAIM tokens ****/ /**** NEVERCLAIM tokens ****/
@ -245,7 +247,8 @@ aut-1: hoa
hoa: header "--BODY--" body "--END--" hoa: header "--BODY--" body "--END--"
hoa: error "--END--" hoa: error "--END--"
string_opt: | STRING string_opt: { $$ = nullptr; }
| STRING { $$ = $1; }
BOOLEAN: 't' | 'f' BOOLEAN: 't' | 'f'
header: format-version header-items header: format-version header-items
@ -495,6 +498,7 @@ header-item: "States:" INT
| "tool:" STRING string_opt | "tool:" STRING string_opt
{ {
delete $2; delete $2;
delete $3;
} }
| "name:" STRING | "name:" STRING
{ {
@ -772,6 +776,7 @@ state: state-name labeled-edges
res.complete = false; res.complete = false;
} }
state-name: "State:" state-label_opt checked-state-num string_opt state-acc_opt state-name: "State:" state-label_opt checked-state-num string_opt state-acc_opt
{ {
res.cur_state = $3; res.cur_state = $3;
@ -783,6 +788,17 @@ state-name: "State:" state-label_opt checked-state-num string_opt state-acc_opt
} }
res.declared_states[$3] = true; res.declared_states[$3] = true;
res.acc_state = $5; res.acc_state = $5;
if ($4)
{
if (!res.state_names)
res.state_names =
new std::vector<std::string>(res.states > 0 ?
res.states : 0);
if (res.state_names->size() < $3 + 1)
res.state_names->resize($3 + 1);
(*res.state_names)[$3] = std::move(*$4);
delete $4;
}
} }
label: '[' label-expr ']' label: '[' label-expr ']'
{ {
@ -1434,6 +1450,8 @@ namespace spot
return r.h; return r.h;
if (!r.h->aut) if (!r.h->aut)
return nullptr; return nullptr;
if (r.state_names)
r.h->aut->set_named_prop("state-names", r.state_names);
if (r.neg_acc_sets) if (r.neg_acc_sets)
fix_acceptance(r); fix_acceptance(r);
if (r.acc_style == State_Acc || if (r.acc_style == State_Acc ||

View file

@ -46,6 +46,7 @@ namespace spot
bool mark_states_ = false; bool mark_states_ = false;
bool opt_scc_ = false; bool opt_scc_ = false;
const_tgba_digraph_ptr aut_; const_tgba_digraph_ptr aut_;
std::vector<std::string>* sn_;
public: public:
dotty_output(std::ostream& os, const char* options) dotty_output(std::ostream& os, const char* options)
@ -107,8 +108,12 @@ namespace spot
void void
process_state(unsigned s) process_state(unsigned s)
{ {
os_ << " " << s << " [label=\"" << escape_str(aut_->format_state(s)) os_ << " " << s << " [label=\"";
<< '"'; if (sn_ && s < sn_->size() && !(*sn_)[s].empty())
os_ << escape_str((*sn_)[s]);
else
os_ << s;
os_ << '"';
if (mark_states_ && aut_->state_is_accepting(s)) if (mark_states_ && aut_->state_is_accepting(s))
os_ << ", peripheries=2"; os_ << ", peripheries=2";
os_ << "]\n"; os_ << "]\n";
@ -132,6 +137,7 @@ namespace spot
void print(const const_tgba_digraph_ptr& aut) void print(const const_tgba_digraph_ptr& aut)
{ {
aut_ = aut; aut_ = aut;
sn_ = aut->get_named_prop<std::vector<std::string>>("state-names");
mark_states_ = !opt_force_acc_trans_ && aut_->is_sba(); mark_states_ = !opt_force_acc_trans_ && aut_->is_sba();
auto si = auto si =
std::unique_ptr<scc_info>(opt_scc_ ? new scc_info(aut) : nullptr); std::unique_ptr<scc_info>(opt_scc_ ? new scc_info(aut) : nullptr);

View file

@ -283,6 +283,7 @@ namespace spot
os << " deterministic"; os << " deterministic";
os << nl; os << nl;
os << "--BODY--" << nl; os << "--BODY--" << nl;
auto sn = aut->get_named_prop<std::vector<std::string>>("state-names");
for (unsigned i = 0; i < num_states; ++i) for (unsigned i = 0; i < num_states; ++i)
{ {
hoa_acceptance this_acc = acceptance; hoa_acceptance this_acc = acceptance;
@ -291,6 +292,8 @@ namespace spot
Hoa_Acceptance_States : Hoa_Acceptance_Transitions); Hoa_Acceptance_States : Hoa_Acceptance_Transitions);
os << "State: " << i; os << "State: " << i;
if (sn && i < sn->size() && !(*sn)[i].empty())
os << " \"" << (*sn)[i] << '"';
if (this_acc == Hoa_Acceptance_States) if (this_acc == Hoa_Acceptance_States)
{ {
acc_cond::mark_t acc = 0U; acc_cond::mark_t acc = 0U;

View file

@ -270,7 +270,7 @@ acc-name: generalized-Buchi 2
Acceptance: 2 Inf(0)&Inf(1) Acceptance: 2 Inf(0)&Inf(1)
properties: trans-labels explicit-labels state-acc complete deterministic properties: trans-labels explicit-labels state-acc complete deterministic
--BODY-- --BODY--
State: 0 {0} State: 0 "foo" {0}
[!0&!1] 2 [!0&!1] 2
[0&!1] 0 [0&!1] 0
[!0&1] 1 [!0&1] 1
@ -280,7 +280,7 @@ State: 1 {1}
[0&!1] 1 [0&!1] 1
[!0&1] 1 [!0&1] 1
[0&1] 1 [0&1] 1
State: 2 {0} State: 2 "sink state" {0}
[!0&!1] 2 [!0&!1] 2
[0&!1] 2 [0&!1] 2
[!0&1] 2 [!0&1] 2
@ -1191,30 +1191,30 @@ acc-name: Buchi
Acceptance: 1 Inf(0) Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc complete properties: trans-labels explicit-labels state-acc complete
--BODY-- --BODY--
State: 0 State: 0 "T0_init"
[5] 5 [5] 5
[t] 4 [t] 4
[0] 3 [0] 3
[0&1&2] 2 [0&1&2] 2
[0&1&2&3 | 0&1&2&4] 1 [0&1&2&3 | 0&1&2&4] 1
State: 1 {0} State: 1 "accept_S1" {0}
[t] 4 [t] 4
[0] 3 [0] 3
[0&1&2] 2 [0&1&2] 2
[0&1&2&3 | 0&1&2&4] 1 [0&1&2&3 | 0&1&2&4] 1
State: 2 State: 2 "T2_S1"
[t] 2 [t] 2
[3 | 4] 1 [3 | 4] 1
State: 3 State: 3 "T1_S1"
[t] 3 [t] 3
[1&2] 2 [1&2] 2
[1&2&3 | 1&2&4] 1 [1&2&3 | 1&2&4] 1
State: 4 State: 4 "T0_S1"
[t] 4 [t] 4
[0] 3 [0] 3
[0&1&2] 2 [0&1&2] 2
[0&1&2&3 | 0&1&2&4] 1 [0&1&2&3 | 0&1&2&4] 1
State: 5 {0} State: 5 "accept_all" {0}
[t] 5 [t] 5
--END-- --END--
EOF EOF
@ -1260,7 +1260,7 @@ acc-name: generalized-Buchi 3
Acceptance: 3 Inf(0)&Inf(1)&Inf(2) Acceptance: 3 Inf(0)&Inf(1)&Inf(2)
properties: trans-labels explicit-labels trans-acc complete properties: trans-labels explicit-labels trans-acc complete
--BODY-- --BODY--
State: 0 State: 0 "(x)"
[5] 1 {0 1 2} [5] 1 {0 1 2}
[t] 2 [t] 2
[0] 2 [0] 2
@ -1270,9 +1270,9 @@ State: 0
[0&3 | 0&4] 2 [0&3 | 0&4] 2
[1&2&3 | 1&2&4] 2 [1&2&3 | 1&2&4] 2
[0&1&2&3 | 0&1&2&4] 2 [0&1&2&3 | 0&1&2&4] 2
State: 1 State: 1 "t"
[t] 1 {0 1 2} [t] 1 {0 1 2}
State: 2 State: 2 "G((F(a) && F((b) && (c))) && F((d) || (e)))"
[t] 2 [t] 2
[0] 2 {0} [0] 2 {0}
[1&2] 2 {1} [1&2] 2 {1}

View file

@ -286,7 +286,7 @@ EOF
diff output expected diff output expected
$autfilt --dot=vcsn >output <<EOF $autfilt -H <<EOF | $autfilt --dot=vcsn >output
HOA: v1 HOA: v1
States: 4 States: 4
Start: 2 Start: 2
@ -296,13 +296,13 @@ acc-name: Buchi
Acceptance: 1 Inf(0) Acceptance: 1 Inf(0)
properties: trans-labels explicit-labels state-acc properties: trans-labels explicit-labels state-acc
--BODY-- --BODY--
State: 0 {0} State: 0 "s0" {0}
[1] 0 [1] 0
State: 1 {0} State: 1 "s1" {0}
[0] 1 [0] 1
State: 2 State: 2 "s2"
[1] 0 [1] 0
State: 3 State: 3 "s3"
[0] 1 [0] 1
--END-- --END--
EOF EOF
@ -314,19 +314,19 @@ digraph G {
I -> 3 I -> 3
subgraph cluster_0 { subgraph cluster_0 {
label="" label=""
1 [label="1"] 1 [label="s1"]
} }
subgraph cluster_1 { subgraph cluster_1 {
label="" label=""
0 [label="0"] 0 [label="s0"]
} }
subgraph cluster_2 { subgraph cluster_2 {
label="" label=""
3 [label="3"] 3 [label="s3"]
} }
0 -> 0 [label="b\n{0}"] 0 -> 0 [label="b\n{0}"]
1 -> 1 [label="a\n{0}"] 1 -> 1 [label="a\n{0}"]
2 [label="2"] 2 [label="s2"]
2 -> 0 [label="b"] 2 -> 0 [label="b"]
3 -> 1 [label="a"] 3 -> 1 [label="a"]
3 -> 0 [label="b"] 3 -> 0 [label="b"]