Skip to content

Commit

Permalink
Merge pull request #7 from TNO/sync
Browse files Browse the repository at this point in the history
Some bugfixes and improvements
  • Loading branch information
Yuri-Blankenstein-TNO authored Jan 11, 2024
2 parents de5aca1 + 6dc4d09 commit e4d9a7a
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class DefaultTimeBoundAnalysis {
}

/** Sets the {@code dependency} time-bound, ensuring that it will never be greater than its duration. */
private def void setSafeTimeBound(Dependency dependency, Long timeBound) {
protected def void setSafeTimeBound(Dependency dependency, Long timeBound) {
if (timeBound === null || dependency.duration === null) {
dependency.timeBound = null
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected long getDefaultTimeBound(final Dependency dependency) {
/**
* Sets the {@code dependency} time-bound, ensuring that it will never be greater than its duration.
*/
private void setSafeTimeBound(final Dependency dependency, final Long timeBound) {
protected void setSafeTimeBound(final Dependency dependency, final Long timeBound) {
if (((timeBound == null) || (dependency.getDuration() == null))) {
dependency.setTimeBound(null);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class TmscIsomorphismMatcher {
boolean failAtEnd, BiPredicate<? super Event, ? super Event> eventEquivalence) {
debug('Matching TMSCs {} and {}', leftTmsc.label, rightTmsc.label)
if (eventMatches === null || eventMatches.isEmpty) {
throw new IllegalArgumentException('This algorithm requires at least 1 event match to start.')
debug('This algorithm requires at least 1 event match to start.')
return TmscMatchResult.EMPTY;
} else if (!failAtEnd && leftTmsc.dependencies.size != rightTmsc.dependencies.size) {
// TMSC are not considered to be isomorphic equivalent when they contain different amounts of dependencies
debug('TMSCs are different: Size: {} != {}', leftTmsc.dependencies.size, rightTmsc.dependencies.size)
Expand All @@ -138,9 +139,9 @@ class TmscIsomorphismMatcher {
if (failAtEnd) {
debug(String.format('TMSCs match for %.2f%%', matchState.result.matchPercentage * 100))
} else if (matchState.result.isFullMatch) {
debug('TMSCs are different!')
} else {
debug('TMSCs are equivalent!')
} else {
debug('TMSCs are different!')
}

return matchState.result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import nl.esi.pps.architecture.implemented.FunctionParameterKind
import nl.esi.pps.architecture.implemented.ImplementedFactory
import nl.esi.pps.tmsc.EntryEvent
import nl.esi.pps.tmsc.Event
import nl.esi.pps.tmsc.Execution
import nl.esi.pps.tmsc.ExitEvent

class FunctionParametersUtil {
Expand All @@ -23,12 +24,34 @@ class FunctionParametersUtil {
private new() {
// Empty for utility classes
}

static def getArgument(Execution execution, String parameterName) {
if (execution === null) {
return null
}
val parameter = execution.function.getParameter(parameterName)
if (parameter === null) {
return null
}
return switch (parameter.kind) {
case IN: execution.entry.getArgument(parameter)
case OUT,
case RETURN : execution.exit.getArgument(parameter)
case IN_OUT: execution.exit.getArgument(parameter) ?: execution.entry.getArgument(parameter)
}
}

static def String getReturnValue(ExitEvent event) {
if (event === null) {
return null
}
return event.getArgument(null as String)
}

static def String getArgument(Event event, String parameterName) {
if (event === null) {
return null
}
val parameter = event.function.getParameter(parameterName)
if (parameter === null) {
return null
Expand All @@ -37,14 +60,23 @@ class FunctionParametersUtil {
}

static def String getArgument(Event event, FunctionParameter parameter) {
if (event === null) {
return null
}
return event.arguments.get(parameter)
}

static def void setReturnValue(ExitEvent event, String value) {
if (event === null) {
return
}
event.setArgument(null as String, value)
}

static def void setArgument(Event event, String parameterName, String value) {
if (event === null) {
return
}
var parameter = event.function.getParameter(parameterName)
val parameterKind = switch (event) {
ExitEvent: {
Expand Down Expand Up @@ -78,7 +110,9 @@ class FunctionParametersUtil {
}

static def void setArgument(Event event, FunctionParameter parameter, String value) {
if (value === null) {
if (event === null) {
return
} else if (value === null) {
event.arguments.removeKey(parameter)
} else {
event.arguments.put(parameter, value)
Expand All @@ -91,6 +125,9 @@ class FunctionParametersUtil {

def static FunctionParameter getParameter(Function function, String parameterName,
FunctionParameterKind parameterKind) {
if (function === null) {
return null
}
val parameter = function.parameters.findFirst[name == parameterName]
if (parameter !== null) {
if (parameterKind !== null && parameter.kind != parameterKind) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,15 @@ final class TmscQueries {
}
}

static def void makeRelativeTiming(TMSC tmsc) {
val fullScope = tmsc.fullScope
if (tmsc instanceof ScopedTMSC) {
ScopedTmscCopier.deriveStartEndTime(tmsc);
}
fullScope.shiftTime(-fullScope.getStartTime());
fullScope.epochTime = false
}

static def void shiftTime(FullScopeTMSC tmsc, long delta) {
tmsc.events.reject[timestamp === null].forEach[timestamp = timestamp + delta]
tmsc.startTime = tmsc.startTime + delta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ public static ITmscMatchResult match(final ITMSC leftTmsc, final ITMSC rightTmsc
public static ITmscMatchResult match(final ITMSC leftTmsc, final ITMSC rightTmsc, final BiMap<Event, Event> eventMatches, final boolean failAtEnd, final BiPredicate<? super Event, ? super Event> eventEquivalence) {
TmscIsomorphismMatcher.LOGGER.debug("Matching TMSCs {} and {}", TmscIsomorphismMatcher.getLabel(leftTmsc), TmscIsomorphismMatcher.getLabel(rightTmsc));
if (((eventMatches == null) || eventMatches.isEmpty())) {
throw new IllegalArgumentException("This algorithm requires at least 1 event match to start.");
TmscIsomorphismMatcher.LOGGER.debug("This algorithm requires at least 1 event match to start.");
return TmscMatchResult.EMPTY;
} else {
if (((!failAtEnd) && (leftTmsc.getDependencies().size() != rightTmsc.getDependencies().size()))) {
TmscIsomorphismMatcher.LOGGER.debug("TMSCs are different: Size: {} != {}", Integer.valueOf(leftTmsc.getDependencies().size()), Integer.valueOf(rightTmsc.getDependencies().size()));
Expand Down Expand Up @@ -318,9 +319,9 @@ public static ITmscMatchResult match(final ITMSC leftTmsc, final ITMSC rightTmsc
} else {
boolean _isFullMatch = matchState.result.isFullMatch();
if (_isFullMatch) {
TmscIsomorphismMatcher.LOGGER.debug("TMSCs are different!");
} else {
TmscIsomorphismMatcher.LOGGER.debug("TMSCs are equivalent!");
} else {
TmscIsomorphismMatcher.LOGGER.debug("TMSCs are different!");
}
}
return matchState.result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import nl.esi.pps.architecture.implemented.ImplementedFactory;
import nl.esi.pps.tmsc.EntryEvent;
import nl.esi.pps.tmsc.Event;
import nl.esi.pps.tmsc.Execution;
import nl.esi.pps.tmsc.ExitEvent;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
Expand All @@ -33,11 +34,54 @@ public class FunctionParametersUtil {
private FunctionParametersUtil() {
}

public static String getArgument(final Execution execution, final String parameterName) {
if ((execution == null)) {
return null;
}
final FunctionParameter parameter = FunctionParametersUtil.getParameter(execution.getFunction(), parameterName);
if ((parameter == null)) {
return null;
}
String _switchResult = null;
FunctionParameterKind _kind = parameter.getKind();
if (_kind != null) {
switch (_kind) {
case IN:
_switchResult = FunctionParametersUtil.getArgument(execution.getEntry(), parameter);
break;
case OUT:
case RETURN:
_switchResult = FunctionParametersUtil.getArgument(execution.getExit(), parameter);
break;
case IN_OUT:
String _elvis = null;
String _argument = FunctionParametersUtil.getArgument(execution.getExit(), parameter);
if (_argument != null) {
_elvis = _argument;
} else {
String _argument_1 = FunctionParametersUtil.getArgument(execution.getEntry(), parameter);
_elvis = _argument_1;
}
_switchResult = _elvis;
break;
default:
break;
}
}
return _switchResult;
}

public static String getReturnValue(final ExitEvent event) {
if ((event == null)) {
return null;
}
return FunctionParametersUtil.getArgument(event, ((String) null));
}

public static String getArgument(final Event event, final String parameterName) {
if ((event == null)) {
return null;
}
final FunctionParameter parameter = FunctionParametersUtil.getParameter(event.getFunction(), parameterName);
if ((parameter == null)) {
return null;
Expand All @@ -46,14 +90,23 @@ public static String getArgument(final Event event, final String parameterName)
}

public static String getArgument(final Event event, final FunctionParameter parameter) {
if ((event == null)) {
return null;
}
return event.getArguments().get(parameter);
}

public static void setReturnValue(final ExitEvent event, final String value) {
if ((event == null)) {
return;
}
FunctionParametersUtil.setArgument(event, ((String) null), value);
}

public static void setArgument(final Event event, final String parameterName, final String value) {
if ((event == null)) {
return;
}
FunctionParameter parameter = FunctionParametersUtil.getParameter(event.getFunction(), parameterName);
FunctionParameterKind _switchResult = null;
boolean _matched = false;
Expand Down Expand Up @@ -106,10 +159,14 @@ public static void setArgument(final Event event, final String parameterName, fi
}

public static void setArgument(final Event event, final FunctionParameter parameter, final String value) {
if ((value == null)) {
event.getArguments().removeKey(parameter);
if ((event == null)) {
return;
} else {
event.getArguments().put(parameter, value);
if ((value == null)) {
event.getArguments().removeKey(parameter);
} else {
event.getArguments().put(parameter, value);
}
}
}

Expand All @@ -118,6 +175,9 @@ public static FunctionParameter getParameter(final Function function, final Stri
}

public static FunctionParameter getParameter(final Function function, final String parameterName, final FunctionParameterKind parameterKind) {
if ((function == null)) {
return null;
}
final Function1<FunctionParameter, Boolean> _function = (FunctionParameter it) -> {
String _name = it.getName();
return Boolean.valueOf(Objects.equal(_name, parameterName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,17 @@ public static <T extends Object> T getAtMostOne(final Iterable<T> source) {
}
}

public static void makeRelativeTiming(final TMSC tmsc) {
final FullScopeTMSC fullScope = tmsc.getFullScope();
if ((tmsc instanceof ScopedTMSC)) {
ScopedTmscCopier.deriveStartEndTime(((ScopedTMSC)tmsc));
}
Long _startTime = fullScope.getStartTime();
long _minus = (-(_startTime).longValue());
TmscQueries.shiftTime(fullScope, _minus);
fullScope.setEpochTime(false);
}

public static void shiftTime(final FullScopeTMSC tmsc, final long delta) {
final Function1<Event, Boolean> _function = (Event it) -> {
Long _timestamp = it.getTimestamp();
Expand Down

0 comments on commit e4d9a7a

Please sign in to comment.