Skip to content
Open
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 @@ -2,6 +2,7 @@

import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -17,6 +18,9 @@
import liquidjava.processor.context.RefinedVariable;
import liquidjava.processor.facade.AliasDTO;
import liquidjava.processor.facade.GhostDTO;
import liquidjava.processor.state_machine.StateMachine;
import liquidjava.processor.state_machine.StateMachineBuilder;
import liquidjava.processor.state_machine.StateSolver;
import liquidjava.rj_language.Predicate;
import liquidjava.rj_language.parsing.RefinementsParser;
import liquidjava.smt.SMTEvaluator;
Expand Down Expand Up @@ -49,6 +53,7 @@ public abstract class TypeChecker extends CtScanner {
protected final Factory factory;
protected final VCChecker vcChecker;
private final Diagnostics diagnostics = Diagnostics.getInstance();
private final Map<String, Optional<StateMachine>> stateMachines = new HashMap<>();

public TypeChecker(Context context, Factory factory) {
this.context = context;
Expand All @@ -64,6 +69,18 @@ public Factory getFactory() {
return factory;
}

/**
* The state machine of {@code className}, built once per checker: the specifications it is built from are all known
* before a checker starts
*/
public Optional<StateMachine> getStateMachine(String className, CtElement element) throws LJError {
if (!stateMachines.containsKey(className)) {
StateSolver solver = new StateSolver(this, element.getPosition());
stateMachines.put(className, StateMachineBuilder.build(this, solver, className, element));
}
return stateMachines.get(className);
}

@Override
public void scan(CtElement element) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,11 @@ private static List<Hint> stateHints(TypeChecker tc, RefinedFunction function, S
if (receiver.isEmpty() || !StateMachineBuilder.canModel(function))
return List.of();
try {
StateSolver solver = new StateSolver(tc, invocation.getPosition());
Optional<StateMachine> machine = StateMachineBuilder.build(tc, solver, function.getTargetClass(),
invocation);
Optional<StateMachine> machine = tc.getStateMachine(function.getTargetClass(), invocation);
if (machine.isEmpty())
return List.of();
Set<State> current = solver.possibleStates(machine.get().states(), state, instanceName);
Set<State> current = new StateSolver(tc, invocation.getPosition()).possibleStates(machine.get().states(),
state, instanceName);
return StateHints.forCall(machine.get(), function, current, receiver.get());
} catch (RuntimeException e) {
// a failure to compute hints must not replace the error being reported
Expand Down
Loading