Menu ▾ ▴

#216 Incorrect C code is generated if an unguarded transition appears before a guarded one

Assigned
closed-fixed
c c++ (2)
5
2020-12-30
2017-07-07
No

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.

3 Attachments

Discussion

  • Charles Rapp

    Charles Rapp - 2019-10-12
    • labels: --> c c++
    • status: open --> open-accepted
    • assigned_to: Charles Rapp
     
  • Charles Rapp

    Charles Rapp - 2019-10-20

    This is the case for the following target languages:

    • C
    • C++
    • C#
    • Groovy
    • Java (-java & -java7
    • Javascript
    • Lua
    • Objective-C
    • Perl
    • PHP
    • Python
    • Ruby
    • Scala
    • Tcl
    • VB.net
     
  • Charles Rapp

    Charles Rapp - 2019-11-17
    • summary: Incorrect C code is generated if an ungurded transition appears before a guarded one --> Incorrect C code is generated if an unguarded transition appears before a guarded one
     
  • David Rea

    David Rea - 2020-11-14

    Can this be closed with the release of 7.1.0?

     
    • Maksim Salau

      Maksim Salau - 2020-11-17

      Hi David,

      I've tested v7.1.0 and it works perfectly. Thanks!

      Regards,
      Maksim

       
  • Charles Rapp

    Charles Rapp - 2020-12-30
    • status: open-accepted --> closed-fixed
     
  • Charles Rapp

    Charles Rapp - 2020-12-30

    Better late than never: this issue was indeed fixed in SMC release 7.1.0.

     

Log in to post a comment.