Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some bugfixes and improvements #7

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,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 @@ -317,7 +317,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 @@ -114,7 +114,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 @@ -139,9 +140,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 @@ -16,6 +16,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 @@ -24,12 +25,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 @@ -38,14 +61,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 @@ -79,7 +111,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 @@ -92,6 +126,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 @@ -625,6 +625,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 @@ -284,7 +284,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 @@ -319,9 +320,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 @@ -17,6 +17,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 @@ -34,11 +35,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 @@ -47,14 +91,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 @@ -107,10 +160,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 @@ -119,6 +176,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 @@ -1274,6 +1274,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