66import it .unive .lisa .analysis .AnalysisState ;
77import it .unive .lisa .analysis .CFGWithAnalysisResults ;
88import it .unive .lisa .analysis .SemanticException ;
9- import it .unive .lisa .analysis .SimpleAbstractState ;
109import it .unive .lisa .analysis .heap .HeapDomain ;
11- import it .unive .lisa .analysis .nonrelational .inference .InferenceSystem ;
12- import it .unive .lisa .analysis .types .InferredTypes ;
1310import it .unive .lisa .analysis .value .ValueDomain ;
1411import it .unive .lisa .caches .Caches ;
1512import it .unive .lisa .checks .ChecksExecutor ;
4845 *
4946 * @author <a href="mailto:[email protected] ">Luca Negrini</a> 5047 *
51- * @param <A> the type of {@link AbstractState} contained into the analysis
52- * state that will be used in the fixpoints
53- * @param <H> the type of {@link HeapDomain} contained into the computed
54- * abstract state that will be used in the fixpoints
55- * @param <V> the type of {@link ValueDomain} contained into the computed
56- * abstract state that will be used in the fixpoints
48+ * @param <A> the type of {@link AbstractState} contained into the analysis
49+ * state that will be used in the analysis fixpoint
50+ * @param <H> the type of {@link HeapDomain} contained into the abstract state
51+ * that will be used in the analysis fixpoint
52+ * @param <V> the type of {@link ValueDomain} contained into the abstract state
53+ * that will be used in the analysis fixpoint
54+ * @param <T> the type of {@link AbstractState} contained into the analysis
55+ * state that will be used in the type inference fixpoint
56+ * @param <HT> the type of {@link HeapDomain} contained into the abstract state
57+ * that will be used in the type inference fixpoint
58+ * @param <VT> the type of {@link ValueDomain} contained into the abstract state
59+ * that will be used in the type inference fixpoint
5760 */
5861public class LiSARunner <A extends AbstractState <A , H , V >,
5962 H extends HeapDomain <H >,
60- V extends ValueDomain <V >> {
63+ V extends ValueDomain <V >,
64+ T extends AbstractState <T , HT , VT >,
65+ HT extends HeapDomain <HT >,
66+ VT extends ValueDomain <VT >> {
6167
6268 private static final String FIXPOINT_EXCEPTION_MESSAGE = "Exception during fixpoint computation" ;
6369
@@ -71,20 +77,30 @@ public class LiSARunner<A extends AbstractState<A, H, V>,
7177
7278 private final A state ;
7379
80+ private final T typeState ;
81+
82+ private final Function <T , ExternalSet <Type >> typeExtractor ;
83+
7484 /**
7585 * Builds the runner.
7686 *
77- * @param conf the configuration of the analysis
78- * @param interproc the interprocedural analysis to use
79- * @param callGraph the call graph to use
80- * @param state the abstract state to use
87+ * @param conf the configuration of the analysis
88+ * @param interproc the interprocedural analysis to use
89+ * @param callGraph the call graph to use
90+ * @param state the abstract state to use for the analysis
91+ * @param typeState the abstract state to use for type inference
92+ * @param typeExtractor the abstract state to use the function that can
93+ * extract runtime types from {@code typeState}
94+ * instances
8195 */
8296 LiSARunner (LiSAConfiguration conf , InterproceduralAnalysis <A , H , V > interproc , CallGraph callGraph ,
83- A state ) {
97+ A state , T typeState , Function < T , ExternalSet < Type >> typeExtractor ) {
8498 this .conf = conf ;
8599 this .interproc = interproc ;
86100 this .callGraph = callGraph ;
87101 this .state = state ;
102+ this .typeState = typeState ;
103+ this .typeExtractor = typeExtractor ;
88104 }
89105
90106 /**
@@ -173,14 +189,9 @@ private void analyze(Collection<CFG> allCFGs, FileManager fileManager) {
173189
174190 @ SuppressWarnings ("unchecked" )
175191 private void inferTypes (FileManager fileManager , Program program , Collection <CFG > allCFGs ) {
176- SimpleAbstractState <H , InferenceSystem <InferredTypes >> typesState ;
177- InterproceduralAnalysis <SimpleAbstractState <H , InferenceSystem <InferredTypes >>, H ,
178- InferenceSystem <InferredTypes >> typesInterproc ;
192+ T typesState = this .typeState .top ();
193+ InterproceduralAnalysis <T , HT , VT > typesInterproc ;
179194 try {
180- // type inference is executed with the simplest abstract state
181- InferenceSystem <InferredTypes > types = new InferenceSystem <>(new InferredTypes ());
182- HeapDomain <?> heap = state == null ? LiSAFactory .getDefaultFor (HeapDomain .class ) : state .getHeapState ();
183- typesState = getInstance (SimpleAbstractState .class , heap , types ).top ();
184195 typesInterproc = getInstance (interproc .getClass ());
185196 typesInterproc .init (program , callGraph );
186197 } catch (AnalysisSetupException | InterproceduralAnalysisException e ) {
@@ -202,18 +213,15 @@ private void inferTypes(FileManager fileManager, Program program, Collection<CFG
202213 ? "Dumping type analysis and propagating it to cfgs"
203214 : "Propagating type information to cfgs" ;
204215 for (CFG cfg : IterationLogger .iterate (LOG , allCFGs , message , "cfgs" )) {
205- Collection <CFGWithAnalysisResults <SimpleAbstractState <H , InferenceSystem <InferredTypes >>, H ,
206- InferenceSystem <InferredTypes >>> results = typesInterproc .getAnalysisResultsOf (cfg );
216+ Collection <CFGWithAnalysisResults <T , HT , VT >> results = typesInterproc .getAnalysisResultsOf (cfg );
207217 if (results .isEmpty ()) {
208218 LOG .warn ("No type information computed for '{}': it is unreachable" , cfg );
209219 continue ;
210220 }
211221
212- CFGWithAnalysisResults <SimpleAbstractState <H , InferenceSystem <InferredTypes >>, H ,
213- InferenceSystem <InferredTypes >> result = null ;
222+ CFGWithAnalysisResults <T , HT , VT > result = null ;
214223 try {
215- for (CFGWithAnalysisResults <SimpleAbstractState <H , InferenceSystem <InferredTypes >>, H ,
216- InferenceSystem <InferredTypes >> res : results )
224+ for (CFGWithAnalysisResults <T , HT , VT > res : results )
217225 if (result == null )
218226 result = res ;
219227 else
@@ -222,36 +230,33 @@ private void inferTypes(FileManager fileManager, Program program, Collection<CFG
222230 throw new AnalysisExecutionException ("Unable to compute type information for " + cfg , e );
223231 }
224232
225- cfg .accept (new TypesPropagator < SimpleAbstractState < H , InferenceSystem < InferredTypes >>, H > (), result );
233+ cfg .accept (new TypesPropagator (), result );
226234
227- CFGWithAnalysisResults <SimpleAbstractState <H , InferenceSystem <InferredTypes >>, H ,
228- InferenceSystem <InferredTypes >> r = result ;
235+ CFGWithAnalysisResults <T , HT , VT > r = result ;
229236 if (conf .isDumpTypeInference ())
230237 dumpCFG (fileManager , "typing___" , r , st -> r .getAnalysisStateAfter (st ).toString ());
231238 }
232239 }
233240
234- private static class TypesPropagator <A extends AbstractState <A , H , InferenceSystem <InferredTypes >>,
235- H extends HeapDomain <H >>
241+ private class TypesPropagator
236242 implements
237- GraphVisitor <CFG , Statement , Edge , CFGWithAnalysisResults <A , H , InferenceSystem < InferredTypes > >> {
243+ GraphVisitor <CFG , Statement , Edge , CFGWithAnalysisResults <T , HT , VT >> {
238244
239245 @ Override
240- public boolean visit (CFGWithAnalysisResults <A , H , InferenceSystem < InferredTypes > > tool , CFG graph ) {
246+ public boolean visit (CFGWithAnalysisResults <T , HT , VT > tool , CFG graph ) {
241247 return true ;
242248 }
243249
244250 @ Override
245- public boolean visit (CFGWithAnalysisResults <A , H , InferenceSystem < InferredTypes > > tool , CFG graph , Edge edge ) {
251+ public boolean visit (CFGWithAnalysisResults <T , HT , VT > tool , CFG graph , Edge edge ) {
246252 return true ;
247253 }
248254
249255 @ Override
250- public boolean visit (CFGWithAnalysisResults <A , H , InferenceSystem < InferredTypes > > tool , CFG graph ,
256+ public boolean visit (CFGWithAnalysisResults <T , HT , VT > tool , CFG graph ,
251257 Statement node ) {
252258 if (tool != null && node instanceof Expression )
253- ((Expression ) node ).setRuntimeTypes (tool .getAnalysisStateAfter (node ).getState ().getValueState ()
254- .getInferredValue ().getRuntimeTypes ());
259+ ((Expression ) node ).setRuntimeTypes (typeExtractor .apply (tool .getAnalysisStateAfter (node ).getState ()));
255260 return true ;
256261 }
257262 }
0 commit comments