Incorrect C code is generated if an unguarded transition appears before a...
Translates state machine into a target programming language.
Brought to you by:
cwrapp
Hi,
SMC v6.6.3 generates invalid code (tested C and C++) if an unguarded transition is defined before a guarded one.
E.g.:
state
{
event nil {}
event [ isCond() ] state {}
}
gives the following C++ code:
:::C++
void fsm_state::event(sampleContext& context)
{
else
{
}
else if ( isCond() )
{
context.getState().Exit(context);
// No actions.
context.setState(fsm::state);
context.getState().Entry(context);
}
}
or C code:
:::C++
static void pkg_fsm_state_event(struct pkg_sampleContext *const fsm)
{
else {
}
else if ( isCond() ) {
/* No actions. */
setState(fsm, &pkg_fsm_state);
}
}
Expected behaviour (to my mind) is either to generate correct code or to fail during code generation.
Changing order of transitions gives correct code.
state
{
event [ isCond() ] state {}
event nil {}
}
gives:
:::C++
void fsm_state::event(sampleContext& context)
{
if ( isCond() )
{
context.getState().Exit(context);
// No actions.
context.setState(fsm::state);
context.getState().Entry(context);
}
else
{
}
}
or:
:::C++
static void pkg_fsm_state_event(struct pkg_sampleContext *const fsm)
{
if ( isCond() ) {
/* No actions. */
setState(fsm, &pkg_fsm_state);
}
else {
}
}
Please see the attached files:
sample.sm - the minimalistic state machine description that reproduces the issue;sample_sm.c - generated C code (java -jar ./Smc.jar -c ./sample.sm);sample_sm.cpp - generated C++ code (java -jar ./Smc.jar -c++ ./sample.sm).P.S.: SMC reports incorrect version.
Smc.jar from smc_6_6_3.tgz gives the following:
$ java -jar ./Smc.jar -version
smc v. 6.6.0
Also README.txt in the released tarball is outdated:
SMC
The State Machine Compiler
(Version: 6.6.2)
Thanks,
Maksim.
This is the case for the following target languages:
Can this be closed with the release of 7.1.0?
Hi David,
I've tested v7.1.0 and it works perfectly. Thanks!
Regards,
Maksim
Better late than never: this issue was indeed fixed in SMC release 7.1.0.