Evaluation of calcs involving metadata access

Hi everyone,

I’m trying to create a calc that returns the documentation’s of an element. Something like this:

package Package {

    part myPart {
        doc /* Docs */
        doc name /* Named doc */
    }

    calc getDocs {
        in element;
        (element meta KerML::Element).documentation
    }

    ref theDocs = getDocs(myPart);
}

What I would expect is that theDocs then holds the two documentations in myPart, however I’m getting a different result with the Syside compiler:

import syside
import syside.query

model, diag = syside.load_model(['model.sysml'])
ref_usage = syside.query.find_by_qualified_name(model, 'Package::theDocs')

value, report = syside.Compiler().evaluate_feature(syside.vm.Context(model.lib), ref_usage, ref_usage)
print(value)
for val in value:
    assert isinstance(val, syside.BoundMetaclass)
    print(val.element)
    assert isinstance(val.element, syside.Documentation)
    print(val.element.body)

It prints None, whereas I would expect:

[<_syside.core.vm.BoundMetaclass object at 0x000002175EA95C80>, <_syside.core.vm.BoundMetaclass object at 0x000002175EA95AA0>]
Package::myPart::(anonymous Documentation)
Docs
Package::myPart::name
Named doc

It seems instead it is accessing the metadata of the elements input of the calc, rather than its bound value (myPart). Or am I understanding something wrong?
Is there a way to explicitly access the bound value of an element?

Greetings,
Jasper

Hi Jasper,

MetadataAccessExpression (element meta ... and element.metadata) binds immediately to the LHS reference, there is no dynamic lookup. You would need to the function to accept metadata reflection instead, and lift metadata access to the call site as getDocs(mypart meta KerML::Element).

Namespace [0, 0] - [14, 0]
  children: OwningMembership [0, 0] - [13, 1]
    target: Package [0, 0] - [13, 1]
      declared_name: NAME [0, 8] - [0, 15]
      children: OwningMembership [2, 4] - [5, 5]
        target: PartUsage [2, 4] - [5, 5]
          declared_name: NAME [2, 9] - [2, 15]
          children: OwningMembership [3, 8] - [3, 22]
            target: Documentation [3, 8] - [3, 22]
              body: REGULAR_COMMENT [3, 12] - [3, 22]
          children: OwningMembership [4, 8] - [4, 32]
            target: Documentation [4, 8] - [4, 32]
              declared_name: NAME [4, 12] - [4, 16]
              body: REGULAR_COMMENT [4, 17] - [4, 32]
      children: OwningMembership [7, 4] - [10, 5]
        target: CalculationUsage [7, 4] - [10, 5]
          declared_name: NAME [7, 9] - [7, 16]
          children: FeatureMembership [8, 8] - [8, 19]
            target: ReferenceUsage [8, 8] - [8, 19]
              direction: FeatureDirectionKind [8, 8] - [8, 10]
              declared_name: NAME [8, 11] - [8, 18]
          result_expression: ResultExpressionMembership [9, 8] - [9, 51]
            target: FeatureChainExpression [9, 8] - [9, 51]
              children: ParameterMembership [9, 8] - [9, 37]
                target: Feature [9, 8] - [9, 37]
                  feature_value: FeatureValue [9, 8] - [9, 37]
                    target: OperatorExpression [9, 9] - [9, 36]
                      children: ParameterMembership [9, 9] - [9, 16]
                        target: Feature [9, 9] - [9, 16]
                          feature_value: FeatureValue [9, 9] - [9, 16]
                            target: MetadataAccessExpression [9, 9] - [9, 16]
                              referenced_element: Membership [9, 9] - [9, 16]
                                target: ElementReference [9, 9] - [9, 16]
                                  segment: NAME [9, 9] - [9, 16]
                      children: ReturnParameterMembership [9, 22] - [9, 36]
                        target: Feature [9, 22] - [9, 36]
                          heritage: FeatureTyping [9, 22] - [9, 36]
                            target: TypeReference [9, 22] - [9, 36]
                              segment: NAME [9, 22] - [9, 27]
                              segment: NAME [9, 29] - [9, 36]
              children: Membership [9, 38] - [9, 51]
                target: FeatureReference [9, 38] - [9, 51]
                  segment: NAME [9, 38] - [9, 51]
      children: OwningMembership [12, 4] - [12, 34]
        target: ReferenceUsage [12, 4] - [12, 34]
          declared_name: NAME [12, 8] - [12, 15]
          feature_value: FeatureValue [12, 16] - [12, 33]
            target: InvocationExpression [12, 18] - [12, 33]
              children: Membership [12, 18] - [12, 25]
                target: TypeReference [12, 18] - [12, 25]
                  segment: NAME [12, 18] - [12, 25]
              children: ParameterMembership [12, 26] - [12, 32]
                target: Feature [12, 26] - [12, 32]
                  feature_value: FeatureValue [12, 26] - [12, 32]
                    target: FeatureReferenceExpression [12, 26] - [12, 32]
                      referent: Membership [12, 26] - [12, 32]
                        target: FeatureReference [12, 26] - [12, 32]
                          segment: NAME [12, 26] - [12, 32]

Hi Daumantas,

Is that (the immediate binding) a language limitation or a limitation from Syside?

Metamodel. The referent is not a parameter hence immediate binding.

Ah that seems like quite a limitation then :frowning:
But thanks for pointing it out!