Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -9,6 +9,7 @@
import liquidjava.rj_language.ast.BinaryExpression;
import liquidjava.rj_language.ast.Expression;
import liquidjava.rj_language.ast.GroupExpression;
import liquidjava.smt.Counterexample;
import liquidjava.utils.Utils;
import spoon.reflect.cu.SourcePosition;
import spoon.reflect.reference.CtTypeReference;
Expand Down Expand Up @@ -123,6 +124,23 @@ public static void smtStart(VCImplication chain, Predicate extraPremise, Predica
System.out.println(SMT_TAG + " " + formatConclusion(conclusion));
}

public static void simplificationInput(Predicate predicate) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

javadoc? also change the function name, since this is printing the unsimplified version it makes little sense to call it simplificationInput in this file - i get it from where it comes from but its not very meaningful

if (!enabled()) {
return;
}
System.out.println(SMT_TAG + " unsimplified: " + predicate);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

dont use the smt_tag for simplification, create a SIM or SPL tag with another color to indicate what phase we are showing. Also use Unsimplified with uppercase

}

public static void counterexampleAssignments(Counterexample counterexample) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

javadoc

if (!enabled() || counterexample == null || counterexample.assignments().isEmpty()) {
return;
}
System.out.println(SMT_TAG + " unfiltered counterexample assignments:");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

same here

for (var assignment : counterexample.assignments()) {
System.out.println(SMT_TAG + " " + assignment.first() + " = " + assignment.second());
}
}

private static String plainLabel(VCImplication node) {
return node.getName() + " : " + simpleType(node.getType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;
import java.util.stream.Collectors;

import liquidjava.api.CommandLineLauncher;
import liquidjava.diagnostics.DebugLog;
import liquidjava.diagnostics.TranslationTable;
import liquidjava.rj_language.ast.Expression;
import liquidjava.rj_language.ast.formatter.VariableFormatter;
Expand Down Expand Up @@ -44,6 +44,8 @@ public String getCounterExampleString() {
if (counterexample == null || counterexample.assignments().isEmpty())
return null;

DebugLog.counterexampleAssignments(counterexample);

List<String> foundVarNames = new ArrayList<>();
found.getValue().getVariableNames(foundVarNames);
// also keep resolved static-final constants (e.g. Integer.MAX_VALUE) referenced by either side of the
Expand All @@ -53,8 +55,8 @@ public String getCounterExampleString() {
List<String> foundAssignments = found.getValue().getConjuncts().stream().map(Expression::toString).toList();
String counterexampleString = counterexample.assignments().stream()
// only include variables that appear in the found value and are not already fixed there
.filter(a -> CommandLineLauncher.cmdArgs.debugMode || (foundVarNames.contains(a.first())
&& !foundAssignments.contains(a.first() + " == " + a.second())))
.filter(a -> foundVarNames.contains(a.first())
&& !foundAssignments.contains(a.first() + " == " + a.second()))
// format as "var == value"
.map(a -> VariableFormatter.format(a.first()) + " == " + a.second())
// join with "&&"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Map;
import java.util.stream.Collectors;

import liquidjava.api.CommandLineLauncher;
import liquidjava.diagnostics.DebugLog;
import liquidjava.diagnostics.errors.LJError;
import liquidjava.diagnostics.errors.NotFoundError;
import liquidjava.processor.context.AliasWrapper;
Expand Down Expand Up @@ -252,14 +252,13 @@ public Expression getExpression() {
}

public ValDerivationNode simplify(Context context) {
DebugLog.simplificationInput(this);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

we should print both unsimplified and simplified predicates one next to the other so its easier to see the changes in the debug info


// collect aliases from context
Map<String, AliasDTO> aliases = new HashMap<>();
for (AliasWrapper aw : context.getAliases()) {
aliases.put(aw.getName(), aw.createAliasDTO());
}
if (CommandLineLauncher.cmdArgs.debugMode) {
return new ValDerivationNode(exp.clone(), null);
}
// simplify expression
return ExpressionSimplifier.simplify(exp.clone(), aliases);
}
Expand Down
Loading