New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parallel state machines must not have the same name #778

Closed
vahdat-ab opened this Issue Mar 15, 2016 · 8 comments

Comments

Projects
None yet
3 participants
@vahdat-ab
Member

vahdat-ab commented Mar 15, 2016

Consider the following example:

class A{
  sm{
    s0{
      goS1-> s1;
    }
    s1{
      t1{
        goT2-> t2;
      }
      t2{ }
      ||
      t1{
        goT4-> t4;
      }
      t4{}
    }
  }
}

We add parallel state machines as nested state machines to a state. It must be guaranteed that two state machines won't get the same name. Currently, we assign the name of the first state to the state machines. Since inside two different state machines, we can have exactly the same name states (initial state) so this approach is going to give exactly the same name to state machines. The result is having the same name for two separate state machines. This is not acceptable in target languages.

Generated code in Java

  //A State Machines
  public enum Sm { s0, s1 }
  public enum SmT1 { Null, t1, t2 }
  public enum SmT1 { Null, t1, t4 }
  private Sm sm;
  private SmT1 smT1;
  private SmT1 smT1;

we have two enums with the name SmT1;

@jblang94

This comment has been minimized.

Contributor

jblang94 commented Feb 11, 2017

@vahdat-ab what is desired behaviour? Should we not allow a nested state machine to have states with the same name, and throw an error? Or, do we rename states when we detect duplicate names (i.e. t1_0, t1_1)? I have been playing around with your example in UmpleOnline.

@jblang94

This comment has been minimized.

Contributor

jblang94 commented Feb 13, 2017

So far, I have identified the area in UmpleInternalParser where parallel state machines are created for the UmpleModel. I have added comments to show my understanding of the code. Is this correct?

// Detects that the user has created a parallel state machine  
...
else if (subToken.is("||"))
      {
        if (fromState.numberOfNestedStateMachines() == 0) { continue; }
        int previousSmIndex = fromState.numberOfNestedStateMachines() - 1;
              StateMachine nestedSm = fromState.getNestedStateMachine(previousSmIndex);
              if (nestedSm.numberOfStates() == 0) { continue; }
              nestedSm.setName(nestedSm.getState(0).getName());
              addNewSm = true;
              isConcurrentState = true;
      }  
...  

// After analyzing the "||" token, the next subtoken we analyze is the "state" token
// From analyzing "||" (subToken's previous value) we know that this state is   
// a parallel state machine
else if (subToken.is("state"))
      {
        ... 
          if (addNewSm)
        {
                  if (isConcurrentState)
                  {
                    nestedStateMachine.setName(s.getName());
                  }
          s.setIsStartState(true);
        }  
       ...
@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Feb 13, 2017

@TimLethbridge what do you thin about the desired behavior in this case?
If we don't use region names equal to the initial states, we might restructure many parts of the system. It means we need region names for any reference to states inside composite states.
In this case, for example, region names can be dynamic based on then the number of regions, such as region1,region2`, etc.

@TimLethbridge

This comment has been minimized.

Member

TimLethbridge commented Feb 13, 2017

I think a rule that says initial states of a set of parallel regions must differ is fine. I would even be fine to say all states in a set of parallel regions must differ in name. I am thinking from a pragmatic modeling perspective: Allowing duplication confuses the model anyway, so raising an error I think is fine. Forcing naming of regions would force extra complexity on the modeler -- more complexity than forcing names of initial states to be distinct.

@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Feb 13, 2017

@jblang94 So we don't need to change renaming regions. You need to make sure these cases are detected and proper messages are sent to users. If these cases are detected and avoided, I believe the generated code should be fine.

@jblang94

This comment has been minimized.

Contributor

jblang94 commented Feb 14, 2017

@vahdat-ab @TimLethbridge
Thank you for your comments. So my understanding now is if we detect that two or more parallel states have the same name during compilation, we will throw an error, stop the compilation, and display an error message to the user. Is this correct? If it is, then I believe I will be making changes within UmpleInternalParser.

@vahdat-ab

This comment has been minimized.

Member

vahdat-ab commented Feb 14, 2017

yes, that's right.

@TimLethbridge

This comment has been minimized.

Member

TimLethbridge commented Feb 14, 2017

You simply need to add the error to en.error with appropriate arguments (and flag it as 2 for error in the correct field of en.error), call the method that raises warnings/errors. The system takes care of displaying the message to the user and stopping.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment