NEW IN 1.1
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
Class declarations allow to define hierarchical data structures. They may contain variable and method declarations as members. This includes inner class declarations.
In SCCharts, variables of a class type are statically instantiated. Hence, read/write access is only permitted on members.
Note there are also struct declarations that are a subset of class declarations since they prohibit the optional declaration of methods.
scchart CounterApplication { output int O class Counter { private int counter void increment() { counter++ } void decrement() { counter-- } int getValue() { return counter } } counter immediate during do O = counter.getValue() initial state A { during do counter.increment() } if counter.getValue() >= 5 go to B final state B }
Class Modeling
TODO
Methods
TODO
Generics
COMING SOON
References
COMING SOON
Host Classes
Class 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 HostCounterApplication { 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() }