LibscopeExecutor.java
package dev.civl.mc.library.scope;
import dev.civl.mc.config.IF.CIVLConfiguration;
import dev.civl.mc.dynamic.IF.SymbolicUtility;
import dev.civl.mc.library.common.BaseLibraryExecutor;
import dev.civl.mc.model.IF.CIVLSource;
import dev.civl.mc.model.IF.ModelFactory;
import dev.civl.mc.model.IF.expression.Expression;
import dev.civl.mc.semantics.IF.Evaluation;
import dev.civl.mc.semantics.IF.Executor;
import dev.civl.mc.semantics.IF.LibraryEvaluatorLoader;
import dev.civl.mc.semantics.IF.LibraryExecutor;
import dev.civl.mc.semantics.IF.LibraryExecutorLoader;
import dev.civl.mc.semantics.IF.SymbolicAnalyzer;
import dev.civl.mc.state.IF.State;
import dev.civl.mc.state.IF.UnsatisfiablePathConditionException;
import dev.civl.sarl.IF.expr.SymbolicExpression;
public class LibscopeExecutor extends BaseLibraryExecutor
implements
LibraryExecutor {
public LibscopeExecutor(String name, Executor primaryExecutor,
ModelFactory modelFactory, SymbolicUtility symbolicUtil,
SymbolicAnalyzer symbolicAnalyzer, CIVLConfiguration civlConfig,
LibraryExecutorLoader libExecutorLoader,
LibraryEvaluatorLoader libEvaluatorLoader) {
super(name, primaryExecutor, modelFactory, symbolicUtil,
symbolicAnalyzer, civlConfig, libExecutorLoader,
libEvaluatorLoader);
}
/**
* Executes a system function call, updating the left hand side expression
* with the returned value if any.
*
* @param state
* The current state.
* @param pid
* The ID of the process that the function call belongs to.
* @param call
* The function call statement to be executed.
* @return The new state after executing the function call.
* @throws UnsatisfiablePathConditionException
*/
@Override
protected Evaluation executeValue(State state, int pid, String process,
CIVLSource source, String functionName, Expression[] arguments,
SymbolicExpression[] argumentValues)
throws UnsatisfiablePathConditionException {
Evaluation callEval = null;
switch (functionName) {
case "$scope_parent" :
callEval = this.executeScopeParent(state, pid, process,
arguments, argumentValues);
break;
}
return callEval;
}
/**
* Executes lhs = $scope_parent($scope s).
*
* @param state
* The state where the computation happens.
* @param pid
* The ID of the process that the executed function call belongs
* to.
* @param lhs
* The left hand side expression of the function call, which is
* to be assigned with the return value.
* @param arguments
* The static arguments of the function call.
* @param argumentValues
* The symbolic expressions of the arguments of the function
* call.
* @return The new state after executing the function call.
* @throws UnsatisfiablePathConditionException
* if the assignment of the left hand side expression fails.
*/
private Evaluation executeScopeParent(State state, int pid, String process,
Expression[] arguments, SymbolicExpression[] argumentValues)
throws UnsatisfiablePathConditionException {
SymbolicExpression scopeValue = argumentValues[0];
int scopeID = stateFactory.getDyscopeId(scopeValue);
int parentID = state.getParentId(scopeID);
SymbolicExpression parentScope = stateFactory.scopeValue(parentID);
return new Evaluation(state, parentScope);
}
}