Skip to content

Commit d7ff095

Browse files
committed
fix wrapper concrete types
1 parent b98f12e commit d7ff095

File tree

9 files changed

+71
-19
lines changed

9 files changed

+71
-19
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/ArrayObjectWrappers.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import org.utbot.framework.plugin.api.UtModel
2525
import org.utbot.framework.plugin.api.UtNullModel
2626
import org.utbot.framework.plugin.api.UtPrimitiveModel
2727
import org.utbot.framework.plugin.api.getIdOrThrow
28-
import org.utbot.framework.plugin.api.idOrNull
2928
import org.utbot.framework.plugin.api.util.id
3029
import org.utbot.framework.plugin.api.util.objectArrayClassId
3130
import org.utbot.framework.plugin.api.util.objectClassId
@@ -34,6 +33,7 @@ import soot.Scene
3433
import soot.SootClass
3534
import soot.SootField
3635
import soot.SootMethod
36+
import soot.Type
3737

3838
val rangeModifiableArrayId: ClassId = RangeModifiableUnlimitedArray::class.id
3939

@@ -264,6 +264,9 @@ class RangeModifiableUnlimitedArrayWrapper : WrapperInterface {
264264
return resultModel
265265
}
266266

267+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
268+
setOf(ARRAY_OBJECT_TYPE)
269+
267270
companion object {
268271
internal val rangeModifiableArrayClass: SootClass
269272
get() = Scene.v().getSootClass(rangeModifiableArrayId.name)
@@ -277,6 +280,7 @@ class RangeModifiableUnlimitedArrayWrapper : WrapperInterface {
277280
}
278281

279282
val associativeArrayId: ClassId = AssociativeArray::class.id
283+
val associativeArrayType: Type = Scene.v().getSootClass(AssociativeArray::class.java.canonicalName).type
280284

281285
class AssociativeArrayWrapper : WrapperInterface {
282286

@@ -415,6 +419,9 @@ class AssociativeArrayWrapper : WrapperInterface {
415419
return model
416420
}
417421

422+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
423+
setOf(associativeArrayType)
424+
418425
private fun Traverser.getStorageArrayField(addr: UtAddrExpression) =
419426
getArrayField(addr, associativeArrayClass, storageField)
420427

utbot-framework/src/main/kotlin/org/utbot/engine/CollectionWrappers.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,22 @@ import org.utbot.framework.plugin.api.UtNullModel
2626
import org.utbot.framework.plugin.api.UtStatementModel
2727
import org.utbot.framework.plugin.api.classId
2828
import org.utbot.framework.plugin.api.getIdOrThrow
29-
import org.utbot.framework.util.graph
3029
import org.utbot.framework.plugin.api.id
3130
import org.utbot.framework.plugin.api.util.booleanClassId
3231
import org.utbot.framework.plugin.api.util.constructorId
3332
import org.utbot.framework.plugin.api.util.id
3433
import org.utbot.framework.plugin.api.util.methodId
3534
import org.utbot.framework.plugin.api.util.objectClassId
35+
import org.utbot.framework.util.graph
3636
import org.utbot.framework.util.nextModelName
37+
import soot.ArrayType
3738
import soot.IntType
3839
import soot.RefType
3940
import soot.Scene
4041
import soot.SootClass
4142
import soot.SootField
4243
import soot.SootMethod
44+
import soot.Type
4345

4446
abstract class BaseOverriddenWrapper(protected val overriddenClassName: String) : WrapperInterface {
4547
val overriddenClass: SootClass = Scene.v().getSootClass(overriddenClassName)
@@ -137,6 +139,9 @@ abstract class BaseContainerWrapper(containerClassName: String) : BaseOverridden
137139
}
138140
}
139141

142+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
143+
setOf(Scene.v().getSootClass(chooseClassIdWithConstructor(type.classId).canonicalName).type)
144+
140145
/**
141146
* Method returns list of parameter models that will be passed to [modificationMethodId]
142147
* while construction modification chain in [UtAssembleModel] for the specified [wrapper]
@@ -405,6 +410,9 @@ private val UT_GENERIC_ASSOCIATIVE_CLASS
405410
private val UT_GENERIC_ASSOCIATIVE_SET_EQUAL_GENERIC_TYPE_SIGNATURE =
406411
UT_GENERIC_ASSOCIATIVE_CLASS.getMethodByName(UtGenericAssociative<*, *>::setEqualGenericType.name).signature
407412

413+
val ARRAY_OBJECT_TYPE: Type
414+
get() = ArrayType.v(OBJECT_TYPE, 1)
415+
408416
val ARRAY_LIST_TYPE: RefType
409417
get() = Scene.v().getSootClass(java.util.ArrayList::class.java.canonicalName).type
410418
val LINKED_LIST_TYPE: RefType

utbot-framework/src/main/kotlin/org/utbot/engine/Mocks.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package org.utbot.engine
22

3+
import java.util.concurrent.atomic.AtomicInteger
4+
import kotlin.reflect.KFunction2
5+
import kotlin.reflect.KFunction5
6+
import kotlinx.collections.immutable.persistentListOf
37
import org.utbot.api.mock.UtMock
4-
import org.utbot.common.packageName
58
import org.utbot.engine.overrides.UtArrayMock
69
import org.utbot.engine.overrides.UtLogicMock
710
import org.utbot.engine.overrides.UtOverrideMock
811
import org.utbot.engine.pc.UtAddrExpression
12+
import org.utbot.engine.util.mockListeners.MockListenerController
913
import org.utbot.framework.plugin.api.ClassId
1014
import org.utbot.framework.plugin.api.FieldId
1115
import org.utbot.framework.plugin.api.MethodId
@@ -14,17 +18,13 @@ import org.utbot.framework.plugin.api.id
1418
import org.utbot.framework.plugin.api.util.id
1519
import org.utbot.framework.plugin.api.util.isRefType
1620
import org.utbot.framework.util.executableId
17-
import java.util.concurrent.atomic.AtomicInteger
18-
import kotlin.reflect.KFunction2
19-
import kotlin.reflect.KFunction5
20-
import kotlinx.collections.immutable.persistentListOf
21-
import org.utbot.engine.util.mockListeners.MockListenerController
2221
import org.utbot.framework.util.isInaccessibleViaReflection
2322
import soot.BooleanType
2423
import soot.RefType
2524
import soot.Scene
2625
import soot.SootClass
2726
import soot.SootMethod
27+
import soot.Type
2828

2929
/**
3030
* Generates mock with address provided.
@@ -307,6 +307,9 @@ class UtMockWrapper(
307307
override fun value(resolver: Resolver, wrapper: ObjectValue): UtModel =
308308
TODO("value on mock called: $this")
309309

310+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
311+
setOf(this.type)
312+
310313
override fun toString() = "UtMock(type=$type, target=$mockInfo)"
311314
}
312315

utbot-framework/src/main/kotlin/org/utbot/engine/ObjectWrappers.kt

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
package org.utbot.engine
22

3+
import java.util.Optional
4+
import java.util.OptionalDouble
5+
import java.util.OptionalInt
6+
import java.util.OptionalLong
7+
import java.util.concurrent.CopyOnWriteArrayList
8+
import kotlin.reflect.KClass
39
import org.utbot.common.WorkaroundReason.MAKE_SYMBOLIC
410
import org.utbot.common.workaround
511
import org.utbot.engine.UtListClass.UT_ARRAY_LIST
@@ -34,12 +40,7 @@ import soot.RefType
3440
import soot.Scene
3541
import soot.SootClass
3642
import soot.SootMethod
37-
import java.util.Optional
38-
import java.util.OptionalDouble
39-
import java.util.OptionalInt
40-
import java.util.OptionalLong
41-
import java.util.concurrent.CopyOnWriteArrayList
42-
import kotlin.reflect.KClass
43+
import soot.Type
4344

4445
typealias TypeToBeWrapped = RefType
4546
typealias WrapperType = RefType
@@ -222,6 +223,11 @@ interface WrapperInterface {
222223
): List<InvokeResult>
223224

224225
fun value(resolver: Resolver, wrapper: ObjectValue): UtModel
226+
227+
/**
228+
* Returns list of types that can be produced by [value] method.
229+
*/
230+
fun getPotentialPossibleTypes(type: Type): Set<Type>
225231
}
226232

227233
// TODO: perhaps we have to have wrapper around concrete value here
@@ -255,4 +261,7 @@ data class ThrowableWrapper(val throwable: Throwable) : WrapperInterface {
255261
}
256262
}
257263
}
264+
265+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
266+
setOf(Scene.v().getSootClass(throwable.javaClass.canonicalName).type)
258267
}

utbot-framework/src/main/kotlin/org/utbot/engine/OptionalWrapper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.utbot.framework.plugin.api.util.objectClassId
2727
import org.utbot.framework.util.nextModelName
2828
import soot.Scene
2929
import soot.SootMethod
30+
import soot.Type
3031

3132
/**
3233
* Auxiliary enum class for specifying an implementation for [OptionalWrapper], that it will use.
@@ -98,6 +99,9 @@ class OptionalWrapper(private val utOptionalClass: UtOptionalClass) : BaseOverri
9899
}
99100
}
100101

102+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
103+
setOf(type)
104+
101105
private fun Resolver.instantiationFactoryCallModel(classId: ClassId, wrapper: ObjectValue, model: UtAssembleModel) : UtExecutableCallModel {
102106
val valueField = FieldId(overriddenClass.id, "value")
103107
val isPresentFieldId = FieldId(overriddenClass.id, "isPresent")

utbot-framework/src/main/kotlin/org/utbot/engine/SecurityManagerWrapper.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import org.utbot.framework.util.nextModelName
99
import soot.Scene
1010
import soot.SootClass
1111
import soot.SootMethod
12+
import soot.Type
1213

1314
class SecurityManagerWrapper : BaseOverriddenWrapper(utSecurityManagerClass.name) {
1415
private val baseModelName: String = "securityManager"
@@ -32,6 +33,9 @@ class SecurityManagerWrapper : BaseOverriddenWrapper(utSecurityManagerClass.name
3233
return UtAssembleModel(addr, classId, modelName, instantiationChain, modificationChain)
3334
}
3435

36+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
37+
setOf(type)
38+
3539
companion object {
3640
val utSecurityManagerClass: SootClass
3741
get() = Scene.v().getSootClass(UtSecurityManager::class.qualifiedName)

utbot-framework/src/main/kotlin/org/utbot/engine/StreamWrappers.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import org.utbot.framework.plugin.api.util.objectClassId
1616
import org.utbot.framework.util.nextModelName
1717
import soot.RefType
1818
import soot.Scene
19+
import soot.Type
1920

2021
/**
2122
* Auxiliary enum class for specifying an implementation for [CommonStreamWrapper], that it will use.
@@ -81,6 +82,9 @@ abstract class StreamWrapper(
8182
}
8283
}
8384

85+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
86+
setOf(STREAM_TYPE)
87+
8488
override fun chooseClassIdWithConstructor(classId: ClassId): ClassId = error("No constructor for Stream")
8589

8690
override val modificationMethodId: MethodId

utbot-framework/src/main/kotlin/org/utbot/engine/Strings.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.utbot.engine
22

33
import com.github.curiousoddman.rgxgen.RgxGen
4+
import kotlin.math.max
5+
import kotlinx.collections.immutable.persistentListOf
6+
import kotlinx.collections.immutable.persistentSetOf
47
import org.utbot.common.unreachableBranch
58
import org.utbot.engine.overrides.strings.UtNativeString
69
import org.utbot.engine.overrides.strings.UtString
@@ -43,15 +46,13 @@ import org.utbot.framework.plugin.api.util.charClassId
4346
import org.utbot.framework.plugin.api.util.constructorId
4447
import org.utbot.framework.plugin.api.util.defaultValueModel
4548
import org.utbot.framework.util.nextModelName
46-
import kotlin.math.max
47-
import kotlinx.collections.immutable.persistentListOf
48-
import kotlinx.collections.immutable.persistentSetOf
4949
import soot.CharType
5050
import soot.IntType
5151
import soot.Scene
5252
import soot.SootClass
5353
import soot.SootField
5454
import soot.SootMethod
55+
import soot.Type
5556

5657
val utStringClass: SootClass
5758
get() = Scene.v().getSootClass(UtString::class.qualifiedName)
@@ -191,6 +192,9 @@ class StringWrapper : BaseOverriddenWrapper(utStringClass.name) {
191192
)
192193
}
193194
}
195+
196+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
197+
setOf(STRING_TYPE)
194198
}
195199

196200
internal val utNativeStringClass = Scene.v().getSootClass(UtNativeString::class.qualifiedName)
@@ -286,6 +290,9 @@ class UtNativeStringWrapper : WrapperInterface {
286290
}
287291

288292
override fun value(resolver: Resolver, wrapper: ObjectValue): UtModel = UtNullModel(STRING_TYPE.classId)
293+
294+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
295+
setOf(STRING_TYPE)
289296
}
290297

291298
sealed class UtAbstractStringBuilderWrapper(className: String) : BaseOverriddenWrapper(className) {
@@ -348,6 +355,9 @@ sealed class UtAbstractStringBuilderWrapper(className: String) : BaseOverriddenW
348355
}
349356
}
350357

358+
override fun getPotentialPossibleTypes(type: Type): Set<Type> =
359+
setOf(STRING_TYPE)
360+
351361
private val SootClass.valueField: SootField
352362
get() = getField("value", CharType.v().arrayType)
353363

utbot-framework/src/main/kotlin/org/utbot/engine/SymbolicValue.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utbot.engine
22

3+
import java.util.Objects
34
import org.utbot.engine.pc.UtAddrExpression
45
import org.utbot.engine.pc.UtExpression
56
import org.utbot.engine.pc.isConcrete
@@ -12,7 +13,6 @@ import org.utbot.engine.pc.mkInt
1213
import org.utbot.engine.pc.mkLong
1314
import org.utbot.engine.pc.mkShort
1415
import org.utbot.engine.pc.toConcrete
15-
import java.util.Objects
1616
import soot.ArrayType
1717
import soot.BooleanType
1818
import soot.ByteType
@@ -179,7 +179,10 @@ fun SymbolicValue.toConcrete(): Any = when (this) {
179179

180180
// TODO: one more constructor?
181181
fun objectValue(type: RefType, addr: UtAddrExpression, implementation: WrapperInterface) =
182-
ObjectValue(TypeStorage(type), addr, Concrete(implementation))
182+
ObjectValue(
183+
TypeStorage(type, implementation.getPotentialPossibleTypes(type)),
184+
addr, Concrete(implementation)
185+
)
183186

184187
val voidValue
185188
get() = PrimitiveValue(VoidType.v(), nullObjectAddr)

0 commit comments

Comments
 (0)