Sinelabore Homepage

Update for SysML v2. This version removes two long-standing restrictions — models may now span several files, and an action can drive a part other than its own. It also adds units, a documented set of diagnostic codes, and a number of correctness fixes in state machines. Highlights since 7.2.6:

  • Models split across files. If an imported package is not defined in the current file, it is loaded from a sibling file next to the primary one, and imports in that file are followed recursively. The single-file restriction is gone.
  • perform on another part. An action can perform an action that belongs to a different part, addressed through a feature chain such as head.inner.setOn. Chains are resolved segment by segment, including features inherited through :>.
  • State machines as usages. A machine can be written as state sm { … } instead of state def sm { … }. This matters: a state definition is owned by the part but not featured by it, so attributes and ports are not accessible from inside it.
  • entry / exit / do distinguish reference from declaration. entry setYellow; performs an action that already exists; entry action setYellow; declares a new, empty one. The accidental second form is reported as W3117.
  • Units. Attribute values may carry units in several notations — qualified ([SI::W]), unqualified ([kg]), symbols (['Ω']), quotients ([km/h]) and products ([SI::kilo*SI::metre]). Different spellings of the same unit are normalized so they compare equal. Values are not converted; a scale mix under + or - is reported as W3115.
  • Bundled standard library stubs. Name-compatible subsets of ScalarValues and ISQ ship with the generator, so subsets ISQ::length binds instead of failing.
  • Diagnostic codes. Errors and warnings now carry stable codes with source positions. They are documented on the new Diagnostics page.
  • Straight-line code for linear activities. An activity without branches or loops is emitted as a plain sequence of statements instead of an enum plus while and switch.
  • Action parameter defaults. An omitted in parameter is filled from the default declared on the action definition; a value given at the call site wins.

Fixes worth calling out:

  • entry, exit and do actions on a child of a parallel state were silently dropped and are now executed.
  • Ports declared on a base part are found from a specializing part; an unresolvable port is reported as E3119 instead of producing code that does not compile.
  • A state machine with parallel regions no longer produces spurious “transition starts in an unknown state” errors.

The documentation gained two pages: Diagnostics and Tooling and Validation, the latter describing how to check a model against the SysML v2 reference implementation and render diagrams from it.

Performing an action of another part#

part def Lamp {
    attribute switchCounter : Natural default 0;
    action setOn  { assign switchCounter := switchCounter + 1; }
    action setOff { assign switchCounter := switchCounter + 1; }
}

part def Controller {
    ref part redLamp    : Lamp;
    ref part yellowLamp : Lamp;

    action switchRed {
        first start;
        then perform redLamp.setOn;
        then done;
    }

    // give the performs a name when the same action is performed twice
    action switchBoth {
        first start;
        then perform action redOn    references redLamp.setOn;
        then perform action yellowOn references yellowLamp.setOn;
        then done;
    }
}

State machine as a usage#

part def Controller {
    attribute msg : Event;

    state sm {                   // usage — 'msg' is accessible here
        entry; then Idle;
        state Idle;
        accept when msg == Event::evGo then Running;
        state Running;
    }
}

Units#

private import ScalarValues::*;
private import SI::*;

part def Measurements {
    attribute qualified : Real = 2.2 [SI::W];
    attribute symbol    : Real = 47 ['Ω'];
    attribute product   : Real = 5 [SI::kilo*SI::metre];

    attribute power     : Real := 12.0 [SI::V] * 2.5 [SI::A];   // no warning
    attribute mixedScale: Real := 5 [km] + 200 [m];             // W3115
}