Skip to content

Comments

ST6RI-840 Constructor expression evaluation (KERML_-224)#645

Merged
seidewitz merged 3 commits intomasterfrom
ST6RI-840
May 1, 2025
Merged

ST6RI-840 Constructor expression evaluation (KERML_-224)#645
seidewitz merged 3 commits intomasterfrom
ST6RI-840

Conversation

@seidewitz
Copy link
Member

@seidewitz seidewitz commented Apr 30, 2025

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;

@seidewitz seidewitz requested a review from himi April 30, 2025 19:13
@seidewitz seidewitz added this to the 2025-04 milestone Apr 30, 2025
@seidewitz seidewitz self-assigned this Apr 30, 2025
@himi
Copy link
Member

himi commented May 1, 2025

I tried your examples, but it did not work as they are:

  • Performances::constructorExpressions should be Performances::constructorEvaluations
  • S(1, 2) should be new S(1, 2)
  • P(1, 2) should be new P(1, 2)

After that, I could visualize then with EVAL style:
Screenshot 2025-04-30 at 11 05 20 PM

Copy link
Member

@himi himi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed it worked with many patterns including the cases using calc. And I also confirmed that case is not model level evaluable.

@seidewitz
Copy link
Member Author

tried your examples, but it did not work as they are: ...

Oops. I fixed the examples in the PR description. Thanks.

@seidewitz seidewitz merged commit 750ebb3 into master May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants