Skip to content

Commit 43747fb

Browse files
committed
ST6RI-906 Fixed some problems with ExpressionEvaluator.
- Corrected instantiateInvocation to copy instantiatedType from the original InvocationExpression, rather than the ownedTyping. - Updated the evaluation of Features so that unbound input parameters are considered to have a null value (rather than returning the Feature itself).
1 parent 5b664b2 commit 43747fb

2 files changed

Lines changed: 23 additions & 14 deletions

File tree

org.omg.sysml.execution/src/org/omg/sysml/execution/expressions/ExpressionEvaluator.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2022-2025 Model Driven Solutions, Inc.
3+
* Copyright (c) 2022-2026 Model Driven Solutions, Inc.
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Lesser General Public License as published by
@@ -27,7 +27,6 @@
2727
import org.omg.sysml.lang.sysml.Element;
2828
import org.omg.sysml.lang.sysml.Expression;
2929
import org.omg.sysml.lang.sysml.Feature;
30-
import org.omg.sysml.lang.sysml.FeatureTyping;
3130
import org.omg.sysml.lang.sysml.FeatureValue;
3231
import org.omg.sysml.lang.sysml.Function;
3332
import org.omg.sysml.lang.sysml.InvocationExpression;
@@ -37,6 +36,7 @@
3736
import org.omg.sysml.util.ElementUtil;
3837
import org.omg.sysml.util.EvaluationUtil;
3938
import org.omg.sysml.util.FeatureUtil;
39+
import org.omg.sysml.util.NamespaceUtil;
4040
import org.omg.sysml.util.TypeUtil;
4141

4242
public class ExpressionEvaluator extends ModelLevelExpressionEvaluator {
@@ -74,13 +74,9 @@ public EList<Element> evaluateInvocation(InvocationExpression expression, Elemen
7474
protected InvocationExpression instantiateInvocation(InvocationExpression expression, Element target) {
7575
InvocationExpression instantiation = SysMLFactory.eINSTANCE.createInvocationExpression();
7676

77-
// Copy typing from original expression.
78-
for (FeatureTyping typing: expression.getOwnedTyping()) {
79-
FeatureTyping newTyping = SysMLFactory.eINSTANCE.createFeatureTyping();
80-
newTyping.setType(typing.getType());
81-
newTyping.setTypedFeature(instantiation);
82-
instantiation.getOwnedRelationship().add(newTyping);
83-
}
77+
// Copy instantiatedType from original expression.
78+
Type instantiatedType = expression.getInstantiatedType();
79+
NamespaceUtil.addMemberTo(instantiation, instantiatedType);
8480

8581
// Add implicit generalization.
8682
ElementUtil.transform(instantiation);
@@ -119,4 +115,15 @@ protected InvocationExpression instantiateInvocation(InvocationExpression expres
119115

120116
return instantiation;
121117
}
118+
119+
@Override
120+
public EList<Element> evaluateFeature(Feature feature, Type type) {
121+
EList<Element> results = super.evaluateFeature(feature, type);
122+
Element result = results == null || results.size() != 1? null: results.get(0);
123+
124+
// Treat an unbound input parameter as if it was null.
125+
return type != null && result instanceof Feature && !(result instanceof Expression) &&
126+
FeatureUtil.isInputParameter((Feature)results.get(0), type)? EvaluationUtil.nullList(): results;
127+
}
128+
122129
}

org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/ExpressionEvaluationTest.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,17 +347,19 @@ public void testIndexOperator() throws Exception {
347347
+ " calc def Test {"
348348
+ " in x;"
349349
+ " in y;"
350-
+ " x"
350+
+ " (x, y)"
351351
+ " }"
352352
+ "}";
353353

354354
@Test
355355
public void testInvocationEvaluation() throws Exception {
356356
SysMLInteractive instance = getSysMLInteractiveInstance();
357357
process(instance, invocationTest);
358-
assertElement("LiteralInteger 1", instance.eval("Test(1, 2)", "InvocationTest"));
359-
assertElement("LiteralInteger 1", instance.eval("Test(x = 1, y = 2)", "InvocationTest"));
360-
assertElement("LiteralInteger 1", instance.eval("Test(y = 2, x = 1)", "InvocationTest"));
358+
assertList(new String[] {"LiteralInteger 1", "LiteralInteger 2"}, instance.eval("Test(1, 2)", "InvocationTest"));
359+
assertList(new String[] {"LiteralInteger 1", "LiteralInteger 2"}, instance.eval("Test(x = 1, y = 2)", "InvocationTest"));
360+
assertList(new String[] {"LiteralInteger 1", "LiteralInteger 2"}, instance.eval("Test(y = 2, x = 1)", "InvocationTest"));
361+
assertList(new String[] {"LiteralInteger 1"}, instance.eval("Test(1)", "InvocationTest"));
362+
assertList(new String[] {"LiteralInteger 2"}, instance.eval("Test(null, 2)", "InvocationTest"));
361363
}
362364

363365
@Test
@@ -591,5 +593,5 @@ public void testTrigFunctionEvaluation() throws Exception {
591593
assertElement("LiteralRational " + 90.0, instance.eval("TrigFunctions::deg(TrigFunctions::pi/2)", null));
592594
assertElement("LiteralRational " + Math.PI/2, instance.eval("TrigFunctions::rad(90)", null));
593595
}
594-
596+
595597
}

0 commit comments

Comments
 (0)