Skip to content

Commit

Permalink
Fixing tests #120
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaneg committed Oct 6, 2023
1 parent fe14abc commit 9827722
Show file tree
Hide file tree
Showing 6 changed files with 230 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ public AnalysisState<A> getAnalysisStateBefore(
}

if (!(st instanceof Expression) || ((Expression) st).getParentStatement() == null)
return lub(predecessorsOf(st), false);
if (getEntrypoints().contains(st))
return entryStates.getState(st);
else
return lub(predecessorsOf(st), false);

// st is not a statement
// st is not a root-level expression
Expand All @@ -175,9 +178,9 @@ public AnalysisState<A> getAnalysisStateBefore(

// last chance: there is no predecessor, so it might be an entry point
// of the analysis
Statement target = ((Expression) st).getRootStatement();
if (getEntrypoints().contains(target))
return entryStates.getState(target);
Statement root = ((Expression) st).getRootStatement();
if (getEntrypoints().contains(root))
return entryStates.getState(root);

return entryStates.lattice.bottom();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class BackwardAnalyzedCFG<A extends AbstractState<A>>
protected final StatementStore<A> results;

/**
* The map storing the entry state of each entry point.
* The map storing the exit state of each exit point.
*/
protected final StatementStore<A> exitStates;

Expand Down Expand Up @@ -91,47 +91,47 @@ public BackwardAnalyzedCFG(
* Builds the control flow graph, storing the given mapping between nodes
* and fixpoint computation results.
*
* @param cfg the original control flow graph
* @param id a {@link ScopeId} meant to identify this specific
* result based on how it has been produced
* @param singleton an instance of the {@link AnalysisState} containing
* the abstract state of the analysis that was
* executed, used to retrieve top and bottom values
* @param entryStates the entry state for each entry point of the cfg
* @param results the results of the fixpoint computation
* @param cfg the original control flow graph
* @param id a {@link ScopeId} meant to identify this specific
* result based on how it has been produced
* @param singleton an instance of the {@link AnalysisState} containing the
* abstract state of the analysis that was executed,
* used to retrieve top and bottom values
* @param exitStates the exit state for each exit point of the cfg
* @param results the results of the fixpoint computation
*/
public BackwardAnalyzedCFG(
CFG cfg,
ScopeId id,
AnalysisState<A> singleton,
Map<Statement, AnalysisState<A>> entryStates,
Map<Statement, AnalysisState<A>> exitStates,
Map<Statement, AnalysisState<A>> results) {
super(cfg);
this.results = new StatementStore<>(singleton);
results.forEach(this.results::put);
this.exitStates = new StatementStore<>(singleton);
entryStates.forEach(this.exitStates::put);
exitStates.forEach(this.exitStates::put);
this.id = id;
}

/**
* Builds the control flow graph, storing the given mapping between nodes
* and fixpoint computation results.
*
* @param cfg the original control flow graph
* @param id a {@link ScopeId} meant to identify this specific
* result based on how it has been produced
* @param entryStates the entry state for each entry point of the cfg
* @param results the results of the fixpoint computation
* @param cfg the original control flow graph
* @param id a {@link ScopeId} meant to identify this specific
* result based on how it has been produced
* @param exitStates the exit state for each exit point of the cfg
* @param results the results of the fixpoint computation
*/
public BackwardAnalyzedCFG(
CFG cfg,
ScopeId id,
StatementStore<A> entryStates,
StatementStore<A> exitStates,
StatementStore<A> results) {
super(cfg);
this.results = results;
this.exitStates = entryStates;
this.exitStates = exitStates;
this.id = id;
}

Expand Down Expand Up @@ -184,7 +184,10 @@ public AnalysisState<A> getAnalysisStateAfter(
}

if (!(st instanceof Expression) || ((Expression) st).getParentStatement() == null)
return lub(followersOf(st), true);
if (getAllExitpoints().contains(st))
return exitStates.getState(st);
else
return lub(followersOf(st), true);

// st is not a statement
// st is not a root-level expression
Expand Down Expand Up @@ -215,7 +218,7 @@ public AnalysisState<A> getEntryState() throws SemanticException {
/**
* Yields the exit state.
*
* @return the entry state of the CFG
* @return the exit state of the CFG
*
* @throws SemanticException if the lub operator fails
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public BackwardOptimizedAnalyzedCFG(
* containing the abstract state of the analysis
* that was executed, used to retrieve top and
* bottom values
* @param entryStates the entry state for each entry point of the cfg
* @param exitStates the exit state for each exit point of the cfg
* @param results the results of the fixpoint computation
* @param interprocedural the analysis that have been used to produce this
* result, and that can be used to unwind the
Expand All @@ -107,10 +107,10 @@ public BackwardOptimizedAnalyzedCFG(
CFG cfg,
ScopeId id,
AnalysisState<A> singleton,
Map<Statement, AnalysisState<A>> entryStates,
Map<Statement, AnalysisState<A>> exitStates,
Map<Statement, AnalysisState<A>> results,
InterproceduralAnalysis<A> interprocedural) {
super(cfg, id, singleton, entryStates, results);
super(cfg, id, singleton, exitStates, results);
this.interprocedural = interprocedural;
}

Expand All @@ -121,7 +121,7 @@ public BackwardOptimizedAnalyzedCFG(
* @param cfg the original control flow graph
* @param id a {@link ScopeId} meant to identify this specific
* result based on how it has been produced
* @param entryStates the entry state for each entry point of the cfg
* @param exitStates the exit state for each exit point of the cfg
* @param results the results of the fixpoint computation
* @param interprocedural the analysis that have been used to produce this
* result, and that can be used to unwind the
Expand All @@ -130,21 +130,21 @@ public BackwardOptimizedAnalyzedCFG(
public BackwardOptimizedAnalyzedCFG(
CFG cfg,
ScopeId id,
StatementStore<A> entryStates,
StatementStore<A> exitStates,
StatementStore<A> results,
InterproceduralAnalysis<A> interprocedural) {
super(cfg, id, entryStates, results);
super(cfg, id, exitStates, results);
this.interprocedural = interprocedural;
}

private BackwardOptimizedAnalyzedCFG(
CFG cfg,
ScopeId id,
StatementStore<A> entryStates,
StatementStore<A> exitStates,
StatementStore<A> results,
StatementStore<A> expanded,
InterproceduralAnalysis<A> interprocedural) {
super(cfg, id, entryStates, results);
super(cfg, id, exitStates, results);
this.interprocedural = interprocedural;
this.expanded = expanded;
}
Expand Down Expand Up @@ -268,7 +268,7 @@ public void init(

@Override
public void fixpoint(
AnalysisState<A> entryState,
AnalysisState<A> exitState,
Class<? extends WorkingSet<Statement>> fixpointWorkingSet,
FixpointConfiguration conf)
throws FixpointException {
Expand All @@ -284,7 +284,7 @@ public Collection<AnalyzedCFG<A>> getAnalysisResultsOf(
@Override
public AnalysisState<A> getAbstractResultOf(
CFGCall call,
AnalysisState<A> entryState,
AnalysisState<A> exitState,
ExpressionSet[] parameters,
StatementStore<A> expressions)
throws SemanticException {
Expand All @@ -295,7 +295,7 @@ public AnalysisState<A> getAbstractResultOf(
FixpointResults<A> precomputed = interprocedural.getFixpointResults();
ScopeToken scope = new ScopeToken(call);
ScopeId id = getId().push(call);
AnalysisState<A> state = entryState.bottom();
AnalysisState<A> state = exitState.bottom();
for (CFG target : call.getTargetedCFGs()) {
AnalysisState<A> res = precomputed.getState(target).getState(id).getExitState();
state = state.lub(unscope(call, scope, res));
Expand All @@ -306,11 +306,11 @@ public AnalysisState<A> getAbstractResultOf(
@Override
public AnalysisState<A> getAbstractResultOf(
OpenCall call,
AnalysisState<A> entryState,
AnalysisState<A> exitState,
ExpressionSet[] parameters,
StatementStore<A> expressions)
throws SemanticException {
return interprocedural.getAbstractResultOf(call, entryState, parameters, expressions);
return interprocedural.getAbstractResultOf(call, exitState, parameters, expressions);
}

@Override
Expand Down
16 changes: 0 additions & 16 deletions lisa/lisa-sdk/src/test/java/it/unive/lisa/TestAbstractState.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ public Type getDynamicTypeOf(
return Untyped.INSTANCE;
}

@Override
public boolean lessOrEqual(
TestAbstractState other)
throws SemanticException {
// TODO Auto-generated method stub
return false;
}

@Override
public TestAbstractState lub(
TestAbstractState other)
throws SemanticException {
// TODO Auto-generated method stub
return null;
}

@Override
public TestAbstractState withTopMemory() {
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package it.unive.lisa;

import it.unive.lisa.analysis.AbstractState;
import it.unive.lisa.analysis.AnalysisState;
import it.unive.lisa.analysis.AnalyzedCFG;
import it.unive.lisa.analysis.SemanticException;
import it.unive.lisa.analysis.StatementStore;
import it.unive.lisa.analysis.lattices.ExpressionSet;
import it.unive.lisa.analysis.symbols.SymbolAliasing;
import it.unive.lisa.conf.FixpointConfiguration;
import it.unive.lisa.interprocedural.FixpointResults;
import it.unive.lisa.interprocedural.InterproceduralAnalysis;
import it.unive.lisa.interprocedural.InterproceduralAnalysisException;
import it.unive.lisa.interprocedural.OpenCallPolicy;
import it.unive.lisa.interprocedural.callgraph.CallGraph;
import it.unive.lisa.interprocedural.callgraph.CallResolutionException;
import it.unive.lisa.program.Application;
import it.unive.lisa.program.cfg.CFG;
import it.unive.lisa.program.cfg.statement.Statement;
import it.unive.lisa.program.cfg.statement.call.CFGCall;
import it.unive.lisa.program.cfg.statement.call.Call;
import it.unive.lisa.program.cfg.statement.call.OpenCall;
import it.unive.lisa.program.cfg.statement.call.UnresolvedCall;
import it.unive.lisa.type.Type;
import it.unive.lisa.util.collections.workset.WorkingSet;
import it.unive.lisa.util.datastructures.graph.algorithms.FixpointException;
import java.util.Collection;
import java.util.Set;

public class TestInterproceduralAnalysis<A extends AbstractState<A>> implements InterproceduralAnalysis<A> {

@Override
public boolean needsCallGraph() {
return false;
}

@Override
public void init(
Application app,
CallGraph callgraph,
OpenCallPolicy policy)
throws InterproceduralAnalysisException {
}

@Override
public void fixpoint(
AnalysisState<A> entryState,
Class<? extends WorkingSet<Statement>> fixpointWorkingSet,
FixpointConfiguration conf)
throws FixpointException {
}

@Override
public Collection<AnalyzedCFG<A>> getAnalysisResultsOf(
CFG cfg) {
return null;
}

@Override
public AnalysisState<A> getAbstractResultOf(
CFGCall call,
AnalysisState<A> entryState,
ExpressionSet[] parameters,
StatementStore<A> expressions)
throws SemanticException {
return null;
}

@Override
public AnalysisState<A> getAbstractResultOf(
OpenCall call,
AnalysisState<A> entryState,
ExpressionSet[] parameters,
StatementStore<A> expressions)
throws SemanticException {
return null;
}

@Override
public Call resolve(
UnresolvedCall call,
Set<Type>[] types,
SymbolAliasing aliasing)
throws CallResolutionException {
return null;
}

@Override
public FixpointResults<A> getFixpointResults() {
return null;
}
}
Loading

0 comments on commit 9827722

Please sign in to comment.