Skip to content

Commit 6fe23f1

Browse files
authored
Merge pull request #727 from Systems-Modeling/ST6RI-886
ST6RI-886 Evaluation of functions from additional model libraries
2 parents fd0b6d2 + 177e6c3 commit 6fe23f1

84 files changed

Lines changed: 1589 additions & 170 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*******************************************************************************
22
* SysML 2 Pilot Implementation
3-
* Copyright (c) 2025 Model Driven Solutions, Inc.
3+
* Copyright (c) 2025, 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
@@ -21,7 +21,11 @@
2121

2222
package org.omg.sysml.execution.expressions;
2323

24-
import org.omg.sysml.execution.expressions.functions.*;
24+
import org.omg.sysml.execution.expressions.functions.data.*;
25+
import org.omg.sysml.execution.expressions.functions.control.*;
26+
import org.omg.sysml.execution.expressions.functions.numerical.*;
27+
import org.omg.sysml.execution.expressions.functions.sequence.*;
28+
import org.omg.sysml.execution.expressions.functions.string.*;
2529

2630
public class LibraryFunctionFactory extends org.omg.sysml.expressions.ModelLevelLibraryFunctionFactory {
2731

@@ -31,15 +35,44 @@ public class LibraryFunctionFactory extends org.omg.sysml.expressions.ModelLevel
3135
protected void initializeFunctionMap() {
3236
super.initializeFunctionMap();
3337

34-
put(new SizeFunction());
35-
put(new IsEmptyFunction());
36-
put(new NotEmptyFunction());
37-
put(new IncludesFunction());
38-
put(new ExcludesFunction());
38+
// ControlFunctions
39+
put(new ExistsFunction());
40+
put(new ForAllFunction());
41+
put(new MinimizeFunction());
42+
put(new MaximizeFunction());
43+
put(new ReduceFunction());
44+
put(new RejectFunction());
45+
put(new SelectOneFunction());
46+
47+
// DataFunctions
48+
put(new MaxFunction());
49+
put(new MinFunction());
3950

51+
// NumericalFunctions
4052
put(new SumFunction());
4153
put(new ProdFunction());
4254

55+
// SequenceFunctions
56+
put(new ExcludesFunction());
57+
put(new ExcludingAtFunction());
58+
put(new ExcludingFunction());
59+
put(new HeadFunction());
60+
put(new IncludesFunction());
61+
put(new IncludesOnlyFunction());
62+
put(new IncludingAtFunction());
63+
put(new IncludingFunction());
64+
put(new IntersectionFunction());
65+
put(new IsEmptyFunction());
66+
put(new LastFunction());
67+
put(new NotEmptyFunction());
68+
put(new SequenceEqualsFunction());
69+
put(new SequenceSameFunction());
70+
put(new SizeFunction());
71+
put(new SubsequenceFunction());
72+
put(new TailFunction());
73+
put(new UnionFunction());
74+
75+
// StringFunctions
4376
put(new StringLengthFunction());
4477
put(new StringSubstringFunction());
4578
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.control;
22+
23+
import org.eclipse.emf.common.util.EList;
24+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
25+
import org.omg.sysml.lang.sysml.Element;
26+
import org.omg.sysml.lang.sysml.InvocationExpression;
27+
import org.omg.sysml.util.EvaluationUtil;
28+
29+
public class ExistsFunction extends ForAllFunction {
30+
31+
@Override
32+
public String getOperatorName() {
33+
return "exists";
34+
}
35+
36+
@Override
37+
public EList<Element> invoke(InvocationExpression invocation, Element target,
38+
ModelLevelExpressionEvaluator evaluator) {
39+
Boolean result = forAll(invocation, target, evaluator, false);
40+
return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(!result);
41+
}
42+
43+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.control;
22+
23+
import org.eclipse.emf.common.util.EList;
24+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
25+
import org.omg.sysml.expressions.functions.control.ControlFunction;
26+
import org.omg.sysml.lang.sysml.Element;
27+
import org.omg.sysml.lang.sysml.Expression;
28+
import org.omg.sysml.lang.sysml.InvocationExpression;
29+
import org.omg.sysml.util.EvaluationUtil;
30+
31+
public class ForAllFunction extends ControlFunction {
32+
33+
@Override
34+
public String getOperatorName() {
35+
return "forAll";
36+
}
37+
38+
public Boolean forAll(InvocationExpression invocation, Element target,
39+
ModelLevelExpressionEvaluator evaluator, Boolean test) {
40+
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
41+
Element expr = evaluator.argumentValue(invocation, 1, target);
42+
if (list == null || !(expr instanceof Expression)) {
43+
return null;
44+
} else {
45+
for (Element value: list) {
46+
if (value == null) {
47+
return null;
48+
} else {
49+
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
50+
if (exprValue == null || exprValue.size() != 1) {
51+
return null;
52+
} else if (!test.equals(EvaluationUtil.valueOf(exprValue.get(0)))) {
53+
return false;
54+
}
55+
}
56+
}
57+
return true;
58+
}
59+
}
60+
61+
@Override
62+
public EList<Element> invoke(InvocationExpression invocation, Element target,
63+
ModelLevelExpressionEvaluator evaluator) {
64+
Boolean result = forAll(invocation, target, evaluator, true);
65+
return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(result);
66+
}
67+
68+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.control;
22+
23+
import java.util.function.BiFunction;
24+
25+
import org.eclipse.emf.common.util.EList;
26+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.Expression;
29+
import org.omg.sysml.lang.sysml.InvocationExpression;
30+
import org.omg.sysml.lang.sysml.Type;
31+
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
32+
import org.omg.sysml.util.EvaluationUtil;
33+
34+
public class MaximizeFunction extends ReduceFunction {
35+
private static final String MAX_FUNCTION = "DataFunctions::max";
36+
37+
@Override
38+
public String getOperatorName() {
39+
return "maximize";
40+
}
41+
42+
@Override
43+
public EList<Element> invoke(InvocationExpression invocation, Element target,
44+
ModelLevelExpressionEvaluator evaluator) {
45+
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
46+
Element expr = evaluator.argumentValue(invocation, 1, target);
47+
if (list == null || !(expr instanceof Expression)) {
48+
return EvaluationUtil.singletonList(invocation);
49+
} else if (list.isEmpty()) {
50+
return EvaluationUtil.nullList();
51+
} else {
52+
return reduce(invocation, list, new BiFunction<>() {
53+
@Override
54+
public Element apply(Element result, Element value) {
55+
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
56+
if (exprValue == null || exprValue.size() != 1) {
57+
return null;
58+
} else if (result == null) {
59+
return exprValue.get(0);
60+
} else {
61+
Type maxFunction = SysMLLibraryUtil.getLibraryType(expr, MAX_FUNCTION);
62+
InvocationExpression maxInvocation = EvaluationUtil.createInvocationOf(maxFunction, result, exprValue.get(0));
63+
EList<Element> newResult = evaluator.evaluateInvocation(maxInvocation, target);
64+
return newResult == null || newResult.size() != 1? null: newResult.get(0);
65+
}
66+
}
67+
});
68+
}
69+
}
70+
71+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*******************************************************************************
2+
* SysML 2 Pilot Implementation
3+
* Copyright (c) 2026 Model Driven Solutions, Inc.
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Lesser General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*
18+
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
19+
*
20+
*******************************************************************************/
21+
package org.omg.sysml.execution.expressions.functions.control;
22+
23+
import java.util.function.BiFunction;
24+
25+
import org.eclipse.emf.common.util.EList;
26+
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
27+
import org.omg.sysml.lang.sysml.Element;
28+
import org.omg.sysml.lang.sysml.Expression;
29+
import org.omg.sysml.lang.sysml.InvocationExpression;
30+
import org.omg.sysml.lang.sysml.Type;
31+
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
32+
import org.omg.sysml.util.EvaluationUtil;
33+
34+
public class MinimizeFunction extends ReduceFunction {
35+
private static final String MIN_FUNCTION = "DataFunctions::min";
36+
37+
@Override
38+
public String getOperatorName() {
39+
return "minimize";
40+
}
41+
42+
@Override
43+
public EList<Element> invoke(InvocationExpression invocation, Element target,
44+
ModelLevelExpressionEvaluator evaluator) {
45+
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
46+
Element expr = evaluator.argumentValue(invocation, 1, target);
47+
if (list == null || !(expr instanceof Expression)) {
48+
return EvaluationUtil.singletonList(invocation);
49+
} else if (list.isEmpty()) {
50+
return EvaluationUtil.nullList();
51+
} else {
52+
return reduce(invocation, list, new BiFunction<>() {
53+
@Override
54+
public Element apply(Element result, Element value) {
55+
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
56+
if (exprValue == null || exprValue.size() != 1) {
57+
return null;
58+
} else if (result == null) {
59+
return exprValue.get(0);
60+
} else {
61+
Type minFunction = SysMLLibraryUtil.getLibraryType(expr, MIN_FUNCTION);
62+
InvocationExpression minInvocation = EvaluationUtil.createInvocationOf(minFunction, result, exprValue.get(0));
63+
EList<Element> newResult = evaluator.evaluateInvocation(minInvocation, target);
64+
return newResult == null || newResult.size() != 1? null: newResult.get(0);
65+
}
66+
}
67+
});
68+
}
69+
}
70+
71+
}

0 commit comments

Comments
 (0)