Annotations

Annotations are currently an experimental work-in-progress language feature. Their design may change in a backward incompatible manner.

Annotations can be added to elements of a CIF specification, to annotate them with extra information. Annotations are a form of structured data, and the CIF type checker checks their validity. Tools that take CIF specifications as input can process the annotations that are attached to elements of the specification, and use the supplied information.

Annotations differ from comments. Comments can also be used to add additional information to a specification. However, comments are completely free form, as you can write anything in them. They can even be used to (temporarily) comment out some parts of the specification. Furthermore, comments are purely for the benefit of the modeler. They are never interpreted by a tool.

Annotations have two main purposes:

Currently, annotations are only supported for input variables and locations of automata, but this will be extended to other elements of specifications in the future.

The following built-in annotations are bundled with CIF:

Category Annotation

Documentation

doc

State

state

Annotations are an extension mechanism, and anyone can define and register their own annotations. Different CIF installations may therefore have different registered annotations. A CIF specification may thus have a warning in one installation, if the annotation is for instance not registered in that installation, while in another installation the annotation does not have a warning, as there it is registered. Different people could define the same annotation in different ways, such that their own installations interpret that annotation differently and impose different constraints for it. Hence, a specification with such annotations may be valid in one installation, and invalid in another.

For more detailed information on annotations, see the reference manual.

Documentation annotations

Documentation can be added to input variables and locations of automata:

@doc($text = "The lower limit sensor of the elevator.")
@doc($text = "Safety sensor.")
input bool ElevatorDownSensor;

The documentation may span multiple lines:

@doc($text =
    "doc with multiple\n" +
    "lines of\n" +
    "text"
)
input bool i;

It is also possible to use for instance constants from the model in the documentation text:

const int MAX_NR_OF_PRODUCTS = 3;

@doc($text = fmt("Sensor 1/%d.", MAX_NR_OF_PRODUCTS))
input bool s1;

This documentation can then be used by CIF tools in various ways. For instance, if the the CIF code generator is used to generate Java code for the above example, then the documentation is included in the generated code:

/**
 * Input variable "ElevatorDownSensor".
 *
 * <p>
 * The lower limit sensor of the elevator.
 * </p>
 *
 * <p>
 * Safety sensor.
 * </p>
 */
public boolean ElevatorDownSensor;

For more detailed information on documentation annotations, see the reference manual.

State annotations

A state annotation adds state information to a location in an automaton. States consist of the current locations of automata and the current values of variables. The typical use of state annotations is for generated models that contain an automaton representing a state space of another model, where each location of that automaton represents a state of the state space. For instance, the CIF explorer may generate CIF models with state spaces represented as automata. For the example from the lesson on synchronizing events, it may generate the following model:

group producer:
  event produce;
  event provide;
end

group consumer:
  event consume;
end

automaton statespace:
  alphabet producer.produce, producer.provide, consumer.consume;

  @state(consumer = "idle", producer = "producing")
  location loc1:
    initial;
    edge producer.produce goto loc2;

  @state(consumer = "idle", producer = "idle")
  location loc2:
    edge producer.provide goto loc3;

  @state(consumer = "consuming", producer = "producing")
  location loc3:
    edge producer.produce goto loc4;
    edge consumer.consume goto loc1;

  @state(consumer = "consuming", producer = "idle")
  location loc4:
    edge consumer.consume goto loc2;
end

This state space consists of four states, each represented by a location of the statespace automaton. For instance, the first state is represented by location loc1, which corresponds to the state where the consumer is idle and the producer is producing.

A location may have multiple state annotations in case it represents multiple states. For instance, the event-based DFA minimization tool may merge locations representing different states to a single location representing multiple states.

For more detailed information on state annotations, see the reference manual.