Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
FeldrinH committed Apr 20, 2023
1 parent 456cb14 commit 4a98a3f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/main/java/abstractdebugging/AbstractDebuggingServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ private List<NodeInfo> findTargetNodes(CFGNodeInfo cfgNode, @Nullable Conditiona
return candidateNodes;
} else {
return candidateNodes.stream()
.filter(n -> condition.evaluate(n, resultsService))
.filter(n -> condition.evaluateCondition(n, resultsService))
.toList();
}
}
Expand Down Expand Up @@ -893,9 +893,8 @@ public CompletableFuture<EvaluateResponse> evaluate(EvaluateArguments args) {
try {
if (ConditionalExpression.hasExplicitMode(args.getExpression())) {
// If explicit mode is set then defer to ConditionalExpression for evaluation.
boolean conditionalResult = ConditionalExpression.fromString(args.getExpression())
.evaluate(frame.getNode(), resultsService);
result = new JsonPrimitive(conditionalResult);
result = ConditionalExpression.fromString(args.getExpression())
.evaluateValue(frame.getNode(), resultsService);
} else {
// If explicit mode is not set evaluate as a C expression using Goblint.
result = resultsService.evaluateExpression(frame.getNode().nodeId(), args.getExpression());
Expand Down
16 changes: 14 additions & 2 deletions src/main/java/abstractdebugging/ConditionalExpression.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package abstractdebugging;

import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;

public record ConditionalExpression(boolean must, String expression) {

private static final String EXPLICIT_MODE_PREFIX = "\\";
Expand Down Expand Up @@ -29,11 +32,11 @@ public static boolean hasExplicitMode(String conditionalExpression) {
}

/**
* Evaluate conditional expression at given node.
* Evaluate expression as conditional at given node.
*
* @throws IllegalArgumentException if evaluating the condition failed.
*/
public boolean evaluate(NodeInfo node, ResultsService resultsService) {
public boolean evaluateCondition(NodeInfo node, ResultsService resultsService) {
try {
var result = resultsService.evaluateIntegerExpression(node.nodeId(), "!!(" + expression + ")");
return must ? result.mustBeBool(true) : result.mayBeBool(true);
Expand All @@ -42,4 +45,13 @@ public boolean evaluate(NodeInfo node, ResultsService resultsService) {
}
}

/**
* Evaluate expression as value at given node.
*
* @throws IllegalArgumentException if evaluating the condition failed.
*/
public JsonElement evaluateValue(NodeInfo node, ResultsService resultsService) {
return new JsonPrimitive(evaluateCondition(node, resultsService));
}

}

0 comments on commit 4a98a3f

Please sign in to comment.