ST6RI-840 Constructor expression evaluation (KERML_-224) by seidewitz · Pull Request #645 · Systems-Modeling/SysML-v2-Pilot-Implementation

The resolution of the following issue, approved in KerML FTF2 Ballot 7 allowed constructor expression to be model-level evaluable.

The update to the ConstructorExpression::modelLevelEvaluable operation from this resolution was already implemented. This PR updates ModelLevelExpressionEvaluator to actually evaluate constructor expressions.

A constructor expression is parsed as an expression whose instantiatedType is instantiated by its result parameter, with argument expressions bound to appropriate features of the instantiatedType. For example, given the (KerML) declaration

struct S {
   feature a;
   feature b;
}

then the constructor expression S(1,2) is semantically equivalent to the result of

expr :> Performances::constructorEvaluations {
    return feature :>> result : S {
        feature :>> a = 1;
        feature :>> b = 2;
    }
}

Therefore, the model-level evaluation of a constructor expression simply returns its result. So, given the following:

feature s = new S(1,2);
feature s_a = s.a;
feature s_b = s.b;

the feature s evaluates to the result parameter of the constructor expression, so that s_a evaluates to the literal integer 1 and s_b evaluates to the literal integer 2.

The following is an equivalent SysML model that evaluates in the same way:

part def P {
    attribute a;
    attribute b;
}
part p = new P(1,2);
attribute p_a = p.a;
attribute p_b = p.b;