Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Related Publications

Towards Object-Oriented Modeling in SCCharts. Alexander Schulz-Rosengarten and Steven Smyth and Michael Mendler. In Proc. Forum on Specification and Design Languages (FDL ’19), Southampton, UK, 2019.


Inheritance

SCCharts support inheritance, similar to the concept of references.

Each root state can extend multiple base states (since the name super states is already used) by listing them after the extends keyword.

Such an state will inherit all declarations, action and regions of the base states. If conflicts arise or a state has a cyclic inheritance hierarchy, a warning will be displayed. If a state is contained multiple times in the inheritance hierarchy its content will inherited only once.

Declarations can have the private keyword to prevent extending SCCharts from accessing these variables.

Root-level regions of base states can be overriden with the override keyword and consequently replace the behavior by the new definition. Anonymous regions (defined without an ID) cannot be overridden.

Regions can also be references similar to states by using the is keyword. If the reference should refer to the implementation in the base state, the super keyword must be used.

scchart MotorWithButton
  extends ButtonBehavior, MotorBehavior {
    
  override region HandleMotor {
    suspend if !buttonPressed
    
    region is super.HandleMotor
  }
}

scchart MotorBehavior {
  output int motorRotation
  
  const int motorRotationMax = 16
  entry do motorRotation = 0
  
  region HandleMotor {
    initial state Increment {
      during do motorRotation++
    } if motorRotation == motorRotationMax
      do motorRotation = 0
      abort to Increment
  }
}

scchart ButtonBehavior {
  input float buttonPosition
  
  bool buttonPressed = false
  private const float threshold = 0.5
  
  region HandleButton {
    initial state Released
      if buttonPosition < threshold
      do buttonPressed = true
      go to Pressed
    
    state Pressed
      if buttonPosition >= threshold
      do buttonPressed = false
      go to Released
  }
}

Classes

TODO

Class Modeling

TODO

Methods

TODO

Generics

COMING SOON

Host Classes

Class/Struct declarations also allow more advanced oo host code integration. Using the host keyword, the class will be treated as a host code type. The declaration allows to mimic the objects API with fields and methods by defining members. These members do not affect the code generation since the host class will be used directly from the host languages. Howerever, in the SCChart itself this allows proper oo access to the host object.

Host classes can be augmented by Scheduling Directives that will affect the ordering of method calls in the SCChart.

Note that the this host class integration is not limited to Java, since host structs can be used for C. Additionally, the generated C code is usually c++ compatible.
You might have to annotate your host class/struct with a @typedef annotation to advice the C code generation to expect the class/struct to be defined via a typedef instead of a named struct.


#resource includes external files in the compilation and simulation of SCCharts.

#resource "Counter.java"

scchart CounterApplication {
  
  input bool CountUp
  output int O
  
  host class Counter {
    void increment()
    void decrement()
    int getValue()
  } counter

  region {
    initial state A ""
      if CountUp do counter.increment();
                 O = counter.getValue() go to A
      if !CountUp do counter.decrement();
                  O = counter.getValue() go to A
  }
}
class Counter {
    private int value = 0;

    public void increment() {
        value++;
    }
    public void decrement() {
        value--;
    }
    public int getValue() {
        return value;
    }
}



#hostcode allows to insert host code above the generated code.

#hostcode "import java.util.List;"
#hostcode "import java.util.LinkedList;"

scchart UsingJavaList {

  output string info = "[]"
  int size = 99
  
  host class "List<Integer>" {
    private schedule {commuting, commuting} order
    bool add(int v) schedule order 0
    int size()
    string toString() schedule order 1
  } list = `new LinkedList()`
  
  during do list.add(size); list.add(size + 1)
  during do size = list.size()
  during do info = list.toString()
}




  • No labels