Skip to content
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2025 Model Driven Solutions, Inc.
* Copyright (c) 2025, 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
Expand All @@ -21,7 +21,11 @@

package org.omg.sysml.execution.expressions;

import org.omg.sysml.execution.expressions.functions.*;
import org.omg.sysml.execution.expressions.functions.data.*;
import org.omg.sysml.execution.expressions.functions.control.*;
import org.omg.sysml.execution.expressions.functions.numerical.*;
import org.omg.sysml.execution.expressions.functions.sequence.*;
import org.omg.sysml.execution.expressions.functions.string.*;

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

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

put(new SizeFunction());
put(new IsEmptyFunction());
put(new NotEmptyFunction());
put(new IncludesFunction());
put(new ExcludesFunction());
// ControlFunctions
put(new ExistsFunction());
put(new ForAllFunction());
put(new MinimizeFunction());
put(new MaximizeFunction());
put(new ReduceFunction());
put(new RejectFunction());
put(new SelectOneFunction());

// DataFunctions
put(new MaxFunction());
put(new MinFunction());

// NumericalFunctions
put(new SumFunction());
put(new ProdFunction());

// SequenceFunctions
put(new ExcludesFunction());
put(new ExcludingAtFunction());
put(new ExcludingFunction());
put(new HeadFunction());
put(new IncludesFunction());
put(new IncludesOnlyFunction());
put(new IncludingAtFunction());
put(new IncludingFunction());
put(new IntersectionFunction());
put(new IsEmptyFunction());
put(new LastFunction());
put(new NotEmptyFunction());
put(new SequenceEqualsFunction());
put(new SequenceSameFunction());
put(new SizeFunction());
put(new SubsequenceFunction());
put(new TailFunction());
put(new UnionFunction());

// StringFunctions
put(new StringLengthFunction());
put(new StringSubstringFunction());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/
package org.omg.sysml.execution.expressions.functions.control;

import org.eclipse.emf.common.util.EList;
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.lang.sysml.InvocationExpression;
import org.omg.sysml.util.EvaluationUtil;

public class ExistsFunction extends ForAllFunction {

@Override
public String getOperatorName() {
return "exists";
}

@Override
public EList<Element> invoke(InvocationExpression invocation, Element target,
ModelLevelExpressionEvaluator evaluator) {
Boolean result = forAll(invocation, target, evaluator, false);
return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(!result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/
package org.omg.sysml.execution.expressions.functions.control;

import org.eclipse.emf.common.util.EList;
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
import org.omg.sysml.expressions.functions.control.ControlFunction;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.lang.sysml.Expression;
import org.omg.sysml.lang.sysml.InvocationExpression;
import org.omg.sysml.util.EvaluationUtil;

public class ForAllFunction extends ControlFunction {

@Override
public String getOperatorName() {
return "forAll";
}

public Boolean forAll(InvocationExpression invocation, Element target,
ModelLevelExpressionEvaluator evaluator, Boolean test) {
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
Element expr = evaluator.argumentValue(invocation, 1, target);
if (list == null || !(expr instanceof Expression)) {
return null;
} else {
for (Element value: list) {
if (value == null) {
return null;
} else {
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
if (exprValue == null || exprValue.size() != 1) {
return null;
} else if (!test.equals(EvaluationUtil.valueOf(exprValue.get(0)))) {
return false;
}
}
}
return true;
}
}

@Override
public EList<Element> invoke(InvocationExpression invocation, Element target,
ModelLevelExpressionEvaluator evaluator) {
Boolean result = forAll(invocation, target, evaluator, true);
return result == null? EvaluationUtil.singletonList(invocation): EvaluationUtil.booleanResult(result);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/
package org.omg.sysml.execution.expressions.functions.control;

import java.util.function.BiFunction;

import org.eclipse.emf.common.util.EList;
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.lang.sysml.Expression;
import org.omg.sysml.lang.sysml.InvocationExpression;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
import org.omg.sysml.util.EvaluationUtil;

public class MaximizeFunction extends ReduceFunction {
private static final String MAX_FUNCTION = "DataFunctions::max";

@Override
public String getOperatorName() {
return "maximize";
}

@Override
public EList<Element> invoke(InvocationExpression invocation, Element target,
ModelLevelExpressionEvaluator evaluator) {
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
Element expr = evaluator.argumentValue(invocation, 1, target);
if (list == null || !(expr instanceof Expression)) {
return EvaluationUtil.singletonList(invocation);
} else if (list.isEmpty()) {
return EvaluationUtil.nullList();
} else {
return reduce(invocation, list, new BiFunction<>() {
@Override
public Element apply(Element result, Element value) {
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
if (exprValue == null || exprValue.size() != 1) {
return null;
} else if (result == null) {
return exprValue.get(0);
} else {
Type maxFunction = SysMLLibraryUtil.getLibraryType(expr, MAX_FUNCTION);
InvocationExpression maxInvocation = EvaluationUtil.createInvocationOf(maxFunction, result, exprValue.get(0));
EList<Element> newResult = evaluator.evaluateInvocation(maxInvocation, target);
return newResult == null || newResult.size() != 1? null: newResult.get(0);
}
}
});
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* SysML 2 Pilot Implementation
* Copyright (c) 2026 Model Driven Solutions, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @license LGPL-3.0-or-later <http://spdx.org/licenses/LGPL-3.0-or-later>
*
*******************************************************************************/
package org.omg.sysml.execution.expressions.functions.control;

import java.util.function.BiFunction;

import org.eclipse.emf.common.util.EList;
import org.omg.sysml.expressions.ModelLevelExpressionEvaluator;
import org.omg.sysml.lang.sysml.Element;
import org.omg.sysml.lang.sysml.Expression;
import org.omg.sysml.lang.sysml.InvocationExpression;
import org.omg.sysml.lang.sysml.Type;
import org.omg.sysml.lang.sysml.util.SysMLLibraryUtil;
import org.omg.sysml.util.EvaluationUtil;

public class MinimizeFunction extends ReduceFunction {
private static final String MIN_FUNCTION = "DataFunctions::min";

@Override
public String getOperatorName() {
return "minimize";
}

@Override
public EList<Element> invoke(InvocationExpression invocation, Element target,
ModelLevelExpressionEvaluator evaluator) {
EList<Element> list = evaluator.evaluateArgument(invocation, 0, target);
Element expr = evaluator.argumentValue(invocation, 1, target);
if (list == null || !(expr instanceof Expression)) {
return EvaluationUtil.singletonList(invocation);
} else if (list.isEmpty()) {
return EvaluationUtil.nullList();
} else {
return reduce(invocation, list, new BiFunction<>() {
@Override
public Element apply(Element result, Element value) {
EList<Element> exprValue = evaluator.evaluateExpression((Expression)expr, target, value);
if (exprValue == null || exprValue.size() != 1) {
return null;
} else if (result == null) {
return exprValue.get(0);
} else {
Type minFunction = SysMLLibraryUtil.getLibraryType(expr, MIN_FUNCTION);
InvocationExpression minInvocation = EvaluationUtil.createInvocationOf(minFunction, result, exprValue.get(0));
EList<Element> newResult = evaluator.evaluateInvocation(minInvocation, target);
return newResult == null || newResult.size() != 1? null: newResult.get(0);
Copy link
Member

@hpdekoning hpdekoning Jan 10, 2026

Choose a reason for hiding this comment

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

I am guessing you meant naming these minFunction, minInvocation. Looks like a copy/paste typo, does not change behavior & result.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, you are right. I've fixed it.

}
}
});
}
}

}
Loading