File tree Expand file tree Collapse file tree 2 files changed +15
-9
lines changed
utbot-framework/src/main/kotlin/org/utbot/framework Expand file tree Collapse file tree 2 files changed +15
-9
lines changed Original file line number Diff line number Diff line change @@ -226,6 +226,8 @@ class AssembleModelGenerator(private val basePackageName: String) {
226226 assembleModel
227227 }
228228
229+ private val modelsInAnalysis = mutableListOf<UtCompositeModel >()
230+
229231 /* *
230232 * Assembles internal structure of [UtCompositeModel] if possible and handles assembling exceptions.
231233 */
@@ -243,7 +245,14 @@ class AssembleModelGenerator(private val basePackageName: String) {
243245 val constructorId = findBestConstructorOrNull(compositeModel)
244246 ? : throw AssembleException (" No default constructor to instantiate an object of the class ${compositeModel.classId} " )
245247
246- val constructorInfo = constructorAnalyzer.analyze(constructorId)
248+ // we do not analyze a constructor which is currently in the analysis
249+ // thus, we do not encounter an infinite loop in self or cross-reference situations
250+ val shouldAnalyzeConstructor = compositeModel !in modelsInAnalysis
251+ modelsInAnalysis.add(compositeModel)
252+
253+ val constructorInfo =
254+ if (shouldAnalyzeConstructor) constructorAnalyzer.analyze(constructorId)
255+ else ConstructorAssembleInfo (constructorId)
247256
248257 val instantiationCall = constructorCall(compositeModel, constructorInfo)
249258 return UtAssembleModel (
@@ -284,6 +293,8 @@ class AssembleModelGenerator(private val basePackageName: String) {
284293 } catch (e: AssembleException ) {
285294 instantiatedModels.remove(compositeModel)
286295 throw e
296+ } finally {
297+ modelsInAnalysis.remove(compositeModel)
287298 }
288299 }
289300
Original file line number Diff line number Diff line change @@ -33,9 +33,9 @@ import soot.jimple.internal.JimpleLocal
3333 * */
3434data class ConstructorAssembleInfo (
3535 val constructorId : ConstructorId ,
36- val params : Map <Int , FieldId >,
37- val setFields : Set <FieldId >,
38- val affectedFields : Set <FieldId >
36+ val params : Map <Int , FieldId > = mapOf() ,
37+ val setFields : Set <FieldId > = setOf() ,
38+ val affectedFields : Set <FieldId > = setOf()
3939)
4040
4141/* *
@@ -116,11 +116,6 @@ class ConstructorAnalyzer {
116116 setFields : MutableSet <FieldId >,
117117 affectedFields : MutableSet <FieldId >,
118118 ): Map <Int , FieldId > {
119- if (sootConstructor in visitedConstructors) {
120- return emptyMap()
121- }
122- visitedConstructors.add(sootConstructor)
123-
124119 val jimpleBody = retrieveJimpleBody(sootConstructor) ? : return emptyMap()
125120 analyzeAssignments(jimpleBody, setFields, affectedFields)
126121
You can’t perform that action at this time.
0 commit comments