Skip to content

Commit 67423d2

Browse files
committed
continue refactor
1 parent ea87705 commit 67423d2

File tree

22 files changed

+79
-182
lines changed

22 files changed

+79
-182
lines changed

utbot-intellij-python/src/main/kotlin/org/utbot/intellij/plugin/language/python/PythonDialogProcessor.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ object PythonDialogProcessor {
137137
.mapNotNull {
138138
val functionName = it.name ?: return@mapNotNull null
139139
val moduleFilename = it.containingFile.virtualFile?.canonicalPath ?: ""
140-
val containingClassId = it.containingClass?.name?.let{ PythonClassId(it) }
140+
val containingClassId = it.containingClass?.name?.let{ cls -> PythonClassId(cls) }
141141
return@mapNotNull PythonMethodHeader(
142142
functionName,
143143
moduleFilename,

utbot-python/src/main/kotlin/org/utbot/python/PythonTestGenerationProcessor.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ object PythonTestGenerationProcessor {
134134

135135
val classId =
136136
if (containingClassName == null)
137-
PythonClassId("$currentPythonModule.TopLevelFunctions")
137+
PythonClassId(currentPythonModule, "TopLevelFunctions")
138138
else
139-
PythonClassId("$currentPythonModule.$containingClassName")
139+
PythonClassId(currentPythonModule, containingClassName)
140140

141141
val methodIds = notEmptyTests.associate {
142142
it.method to PythonMethodId(

utbot-python/src/main/kotlin/org/utbot/python/evaluation/serialiation/PythonObjectParser.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ sealed class MemoryObject(
4747
val kind: String,
4848
val module: String,
4949
val comparable: Boolean,
50-
)
50+
) {
51+
val qualname: String = if (module.isEmpty()) kind else "$module.$kind"
52+
}
5153

5254
class ReprMemoryObject(
5355
id: String,
@@ -159,7 +161,7 @@ fun MemoryObject.toPythonTree(memoryDump: MemoryDump): PythonTree.PythonTreeNode
159161
val elementsMap = items.withIndex().associate {
160162
it.index to memoryDump.getById(it.value).toPythonTree(memoryDump)
161163
}.toMutableMap()
162-
when (this.kind) {
164+
when (this.qualname) {
163165
"builtins.tuple" -> {
164166
PythonTree.TupleNode(this.id.toLong(), elementsMap)
165167
}
@@ -178,7 +180,7 @@ fun MemoryObject.toPythonTree(memoryDump: MemoryDump): PythonTree.PythonTreeNode
178180
val dictitemsObjs = memoryDump.getById(dictitems) as DictMemoryObject
179181
PythonTree.ReduceNode(
180182
this.id.toLong(),
181-
PythonClassId(this.kind),
183+
PythonClassId(this.kind, this.module),
182184
PythonClassId(this.constructor),
183185
arguments.items.map { memoryDump.getById(it).toPythonTree(memoryDump) },
184186
stateObjs.items.entries.associate {

utbot-python/src/main/kotlin/org/utbot/python/framework/api/python/PythonApi.kt

Lines changed: 4 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ const val pythonBuiltinsModuleName = "builtins"
1818

1919
class PythonClassId(
2020
val moduleName: String,
21-
name: String,
22-
) : ClassId(name) {
21+
val typeName: String,
22+
) : ClassId("$moduleName.$typeName") {
2323
constructor(fullName: String) : this(
2424
moduleOfType(fullName) ?: pythonBuiltinsModuleName,
2525
fullName.removePrefix(moduleOfType(fullName) ?: pythonBuiltinsModuleName).removePrefix(".")
2626
)
2727
override fun toString(): String = canonicalName
2828
val rootModuleName: String = moduleName.split(".").first()
29-
override val simpleName: String = name
30-
override val canonicalName = "$moduleName.$name"
29+
override val simpleName: String = typeName
30+
override val canonicalName = name
3131
override val packageName = moduleName
3232
}
3333

@@ -84,104 +84,3 @@ class PythonTreeModel(
8484
return tree.hashCode()
8585
}
8686
}
87-
88-
class PythonDefaultModel(
89-
val repr: String,
90-
classId: PythonClassId
91-
): PythonModel(classId) {
92-
override fun toString() = repr
93-
}
94-
95-
class PythonPrimitiveModel(
96-
val value: Any,
97-
classId: PythonClassId
98-
): PythonModel(classId) {
99-
override fun toString() = "$value"
100-
}
101-
102-
class PythonBoolModel(val value: Boolean): PythonModel(classId) {
103-
override fun toString() =
104-
if (value) "True" else "False"
105-
companion object {
106-
val classId = PythonClassId("builtins.bool")
107-
}
108-
}
109-
110-
class PythonInitObjectModel(
111-
val type: String,
112-
val initValues: List<PythonModel>
113-
): PythonModel(PythonClassId(type)) {
114-
override fun toString(): String {
115-
val params = initValues.joinToString(separator = ", ") { it.toString() }
116-
return "$type($params)"
117-
}
118-
119-
override val allContainingClassIds: Set<PythonClassId>
120-
get() = super.allContainingClassIds + initValues.flatMap { it.allContainingClassIds }
121-
}
122-
123-
class PythonListModel(
124-
val length: Int = 0,
125-
val stores: List<PythonModel>
126-
) : PythonModel(classId) {
127-
override fun toString() =
128-
(0 until length).joinToString(", ", "[", "]") { stores[it].toString() }
129-
130-
override val allContainingClassIds: Set<PythonClassId>
131-
get() = super.allContainingClassIds + stores.flatMap { it.allContainingClassIds }
132-
133-
companion object {
134-
val classId = PythonClassId("builtins.list")
135-
}
136-
}
137-
138-
class PythonTupleModel(
139-
val length: Int = 0,
140-
val stores: List<PythonModel>
141-
) : PythonModel(classId) {
142-
override fun toString() =
143-
(0 until length).joinToString(", ", "(", ")") { stores[it].toString() }
144-
145-
override val allContainingClassIds: Set<PythonClassId>
146-
get() = super.allContainingClassIds + stores.flatMap { it.allContainingClassIds }
147-
148-
companion object {
149-
val classId = PythonClassId("builtins.tuple")
150-
}
151-
}
152-
153-
class PythonDictModel(
154-
val length: Int = 0,
155-
val stores: Map<PythonModel, PythonModel>
156-
) : PythonModel(classId) {
157-
override fun toString() = withToStringThreadLocalReentrancyGuard {
158-
stores.entries.joinToString(", ", "{", "}") { "${it.key}: ${it.value}" }
159-
}
160-
161-
override val allContainingClassIds: Set<PythonClassId>
162-
get() = super.allContainingClassIds +
163-
stores.entries.flatMap { it.key.allContainingClassIds + it.value.allContainingClassIds }
164-
165-
companion object {
166-
val classId = PythonClassId("builtins.dict")
167-
}
168-
}
169-
170-
class PythonSetModel(
171-
val length: Int = 0,
172-
val stores: Set<PythonModel>
173-
) : PythonModel(classId) {
174-
override fun toString() = withToStringThreadLocalReentrancyGuard {
175-
if (stores.isEmpty())
176-
"set()"
177-
else
178-
stores.joinToString(", ", "{", "}") { it.toString() }
179-
}
180-
181-
override val allContainingClassIds: Set<PythonClassId>
182-
get() = super.allContainingClassIds + stores.flatMap { it.allContainingClassIds }
183-
184-
companion object {
185-
val classId = PythonClassId("builtins.set")
186-
}
187-
}

utbot-python/src/main/kotlin/org/utbot/python/framework/api/python/PythonTree.kt

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

33
import org.utbot.python.framework.api.python.util.pythonBoolClassId
4+
import org.utbot.python.framework.api.python.util.pythonDictClassId
45
import org.utbot.python.framework.api.python.util.pythonFloatClassId
56
import org.utbot.python.framework.api.python.util.pythonIntClassId
7+
import org.utbot.python.framework.api.python.util.pythonListClassId
68
import org.utbot.python.framework.api.python.util.pythonNoneClassId
9+
import org.utbot.python.framework.api.python.util.pythonObjectClassId
10+
import org.utbot.python.framework.api.python.util.pythonSetClassId
711
import org.utbot.python.framework.api.python.util.pythonStrClassId
12+
import org.utbot.python.framework.api.python.util.pythonTupleClassId
813
import org.utbot.python.framework.api.python.util.toPythonRepr
914
import org.utbot.python.newtyping.general.Type
1015
import org.utbot.python.newtyping.pythonTypeName
@@ -106,7 +111,7 @@ object PythonTree {
106111
class ListNode(
107112
id: Long,
108113
val items: MutableMap<Int, PythonTreeNode>
109-
) : PythonTreeNode(id, PythonClassId("builtins.list")) {
114+
) : PythonTreeNode(id, pythonListClassId) {
110115
constructor(items: MutableMap<Int, PythonTreeNode>) : this(PythonIdGenerator.createId(), items)
111116

112117
override val children: List<PythonTreeNode>
@@ -124,7 +129,7 @@ object PythonTree {
124129
class DictNode(
125130
id: Long,
126131
val items: MutableMap<PythonTreeNode, PythonTreeNode>
127-
) : PythonTreeNode(id, PythonClassId("builtins.dict")) {
132+
) : PythonTreeNode(id, pythonDictClassId) {
128133
constructor(items: MutableMap<PythonTreeNode, PythonTreeNode>) : this(PythonIdGenerator.createId(), items)
129134

130135
override val children: List<PythonTreeNode>
@@ -144,7 +149,7 @@ object PythonTree {
144149
class SetNode(
145150
id: Long,
146151
val items: MutableSet<PythonTreeNode>
147-
) : PythonTreeNode(id, PythonClassId("builtins.set")) {
152+
) : PythonTreeNode(id, pythonSetClassId) {
148153
constructor(items: MutableSet<PythonTreeNode>) : this(PythonIdGenerator.createId(), items)
149154

150155
override val children: List<PythonTreeNode>
@@ -167,7 +172,7 @@ object PythonTree {
167172
class TupleNode(
168173
id: Long,
169174
val items: MutableMap<Int, PythonTreeNode>
170-
) : PythonTreeNode(id, PythonClassId("builtins.tuple")) {
175+
) : PythonTreeNode(id, pythonTupleClassId) {
171176
constructor(items: MutableMap<Int, PythonTreeNode>) : this(PythonIdGenerator.createId(), items)
172177

173178
override val children: List<PythonTreeNode>
@@ -244,7 +249,7 @@ object PythonTree {
244249

245250
fun fromObject(): PrimitiveNode {
246251
return PrimitiveNode(
247-
PythonClassId("builtins.object"),
252+
pythonObjectClassId,
248253
"object()"
249254
)
250255
}

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/PythonCodeGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import org.utbot.python.newtyping.pythonModules
4343
import org.utbot.python.newtyping.pythonTypeRepresentation
4444
import org.utbot.python.framework.codegen.toPythonRawString
4545
import org.utbot.python.newtyping.pythonDescription
46+
import org.utbot.python.newtyping.pythonName
4647

4748
class PythonCodeGenerator(
4849
classUnderTest: ClassId,
@@ -139,7 +140,7 @@ class PythonCodeGenerator(
139140
if (containingClass == null)
140141
method.name
141142
else
142-
"${containingClass.pythonDescription().name.name}.${method.name}"
143+
"${containingClass.pythonName()}.${method.name}"
143144
if (functionModule.isNotEmpty()) {
144145
functionTextName = "$functionModule.$functionTextName"
145146
}

utbot-python/src/main/kotlin/org/utbot/python/framework/codegen/model/constructor/tree/PythonCgVariableConstructor.kt

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,18 @@ class PythonCgVariableConstructor(cgContext: CgContext) : CgVariableConstructor(
2121
private val nameGenerator = CgComponents.getNameGeneratorBy(context)
2222

2323
override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
24-
val baseName = name ?: nameGenerator.nameFrom(model.classId)
2524
return valueByModel.getOrPut(model) {
2625
when (model) {
27-
is PythonBoolModel -> {
28-
CgLiteral(model.classId, model.value)
29-
}
30-
is PythonPrimitiveModel -> {
31-
CgLiteral(model.classId, model.value)
32-
}
3326
is PythonTreeModel -> {
3427
val (value, arguments) = pythonBuildObject(model.tree)
3528
CgPythonTree(model.classId, model.tree, value, arguments)
3629
}
37-
is PythonInitObjectModel -> {
38-
constructInitObjectModel(model, baseName)
39-
}
40-
is PythonDictModel -> CgPythonDict(model.stores.map {
41-
getOrCreateVariable(it.key) to getOrCreateVariable(
42-
it.value
43-
)
44-
}.toMap())
45-
46-
is PythonListModel -> CgPythonList(model.stores.map { getOrCreateVariable(it) })
47-
is PythonSetModel -> CgPythonSet(model.stores.map { getOrCreateVariable(it) }.toSet())
48-
is PythonTupleModel -> CgPythonTuple(model.stores.map { getOrCreateVariable(it) })
49-
is PythonDefaultModel -> CgPythonRepr(model.classId, model.repr)
5030
is PythonModel -> error("Unexpected PythonModel: ${model::class}")
5131
else -> super.getOrCreateVariable(model, name)
5232
}
5333
}
5434
}
5535

56-
private fun declareOrGet(model: UtModel): CgValue = valueByModel[model] ?: getOrCreateVariable(model)
57-
58-
private fun constructInitObjectModel(model: PythonInitObjectModel, baseName: String): CgVariable {
59-
return newVar(model.classId, baseName) {
60-
CgConstructorCall(
61-
ConstructorId(model.classId, model.initValues.map { it.classId }),
62-
model.initValues.map { getOrCreateVariable(it) }
63-
)
64-
}
65-
}
66-
6736
private fun pythonBuildObject(objectNode: PythonTree.PythonTreeNode): Pair<CgValue, List<CgStatement>> {
6837
return when (objectNode) {
6938
is PythonTree.PrimitiveNode -> {
@@ -120,7 +89,6 @@ class PythonCgVariableConstructor(cgContext: CgContext) : CgVariableConstructor(
12089
val obj = newVar(objectNode.type) {
12190
constructorCall
12291
}
123-
// obj `=` constructorCall
12492

12593
(context.cgLanguageAssistant as PythonCgLanguageAssistant).memoryObjects[id] = obj
12694
(context.cgLanguageAssistant as PythonCgLanguageAssistant).memoryObjectsModels[id] = objectNode
@@ -138,7 +106,6 @@ class PythonCgVariableConstructor(cgContext: CgContext) : CgVariableConstructor(
138106
}
139107

140108
state.forEach { (key, value) ->
141-
// val fieldAccess = CgFieldAccess(obj, FieldId(objectNode.type, key))
142109
obj[FieldId(objectNode.type, key)] `=` value
143110
}
144111
listitems.forEach {

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/BoolValueProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.utbot.fuzzing.ValueProvider
55
import org.utbot.fuzzing.seeds.Bool
66
import org.utbot.fuzzing.seeds.KnownValue
77
import org.utbot.python.framework.api.python.PythonTree
8+
import org.utbot.python.framework.api.python.util.pythonBoolClassId
89
import org.utbot.python.fuzzing.PythonFuzzedValue
910
import org.utbot.python.fuzzing.PythonMethodDescription
1011
import org.utbot.python.fuzzing.provider.utils.generateSummary
@@ -14,7 +15,7 @@ import org.utbot.python.newtyping.pythonTypeName
1415

1516
object BoolValueProvider : ValueProvider<Type, PythonFuzzedValue, PythonMethodDescription>{
1617
override fun accept(type: Type): Boolean {
17-
return type.pythonTypeName() == "builtins.bool" || type.isAny()
18+
return type.pythonTypeName() == pythonBoolClassId.canonicalName || type.isAny()
1819
}
1920

2021
override fun generate(description: PythonMethodDescription, type: Type) = sequence {

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/BytearrayValueProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.utbot.python.newtyping.pythonTypeRepresentation
1313

1414
object BytearrayValueProvider : ValueProvider<Type, PythonFuzzedValue, PythonMethodDescription> {
1515
override fun accept(type: Type): Boolean {
16-
return type.pythonTypeName() == "builtins.bytearray"
16+
return type.pythonTypeName() == pythonBytearrayClassId.canonicalName
1717
}
1818

1919
override fun generate(description: PythonMethodDescription, type: Type) = sequence {

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/BytesValueProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.utbot.python.newtyping.pythonTypeRepresentation
1313

1414
object BytesValueProvider : ValueProvider<Type, PythonFuzzedValue, PythonMethodDescription> {
1515
override fun accept(type: Type): Boolean {
16-
return type.pythonTypeName() == "builtins.bytes"
16+
return type.pythonTypeName() == pythonBytesClassId.canonicalName
1717
}
1818

1919
override fun generate(description: PythonMethodDescription, type: Type) = sequence {

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/ComplexValueProvider.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import org.utbot.python.newtyping.pythonTypeRepresentation
1414

1515
object ComplexValueProvider : ValueProvider<Type, PythonFuzzedValue, PythonMethodDescription> {
1616
override fun accept(type: Type): Boolean {
17-
return type.pythonTypeName() == "builtins.complex" || type.isAny()
17+
return type.pythonTypeName() == pythonComplexClassId.canonicalName || type.isAny()
1818
}
1919

2020
override fun generate(description: PythonMethodDescription, type: Type) = sequence {

utbot-python/src/main/kotlin/org/utbot/python/fuzzing/provider/DictValueProvider.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.utbot.fuzzing.Routine
44
import org.utbot.fuzzing.Seed
55
import org.utbot.fuzzing.ValueProvider
66
import org.utbot.python.framework.api.python.PythonTree
7+
import org.utbot.python.framework.api.python.util.pythonDictClassId
78
import org.utbot.python.fuzzing.PythonFuzzedValue
89
import org.utbot.python.fuzzing.PythonMethodDescription
910
import org.utbot.python.newtyping.general.Type
@@ -13,7 +14,7 @@ import org.utbot.python.newtyping.pythonTypeRepresentation
1314

1415
object DictValueProvider : ValueProvider<Type, PythonFuzzedValue, PythonMethodDescription> {
1516
override fun accept(type: Type): Boolean {
16-
return type.pythonTypeName() == "builtins.dict"
17+
return type.pythonTypeName() == pythonDictClassId.canonicalName
1718
}
1819

1920
override fun generate(description: PythonMethodDescription, type: Type) = sequence {

0 commit comments

Comments
 (0)