Skip to content

Commit ea87705

Browse files
committed
Continue separate
1 parent 821098a commit ea87705

File tree

4 files changed

+36
-28
lines changed

4 files changed

+36
-28
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,68 +45,73 @@ class MemoryDump(
4545
sealed class MemoryObject(
4646
val id: String,
4747
val kind: String,
48+
val module: String,
4849
val comparable: Boolean,
4950
)
5051

5152
class ReprMemoryObject(
5253
id: String,
5354
kind: String,
55+
module: String,
5456
comparable: Boolean,
5557
val value: String,
56-
): MemoryObject(id, kind, comparable)
58+
): MemoryObject(id, kind, module, comparable)
5759

5860
class ListMemoryObject(
5961
id: String,
6062
kind: String,
63+
module: String,
6164
comparable: Boolean,
6265
val items: List<String>,
63-
): MemoryObject(id, kind, comparable)
66+
): MemoryObject(id, kind, module, comparable)
6467

6568
class DictMemoryObject(
6669
id: String,
6770
kind: String,
71+
module: String,
6872
comparable: Boolean,
6973
val items: Map<String, String>,
70-
): MemoryObject(id, kind, comparable)
74+
): MemoryObject(id, kind, module, comparable)
7175

7276
class ReduceMemoryObject(
7377
id: String,
7478
kind: String,
79+
module: String,
7580
comparable: Boolean,
7681
val constructor: String,
7782
val args: String,
7883
val state: String,
7984
val listitems: String,
8085
val dictitems: String
81-
): MemoryObject(id, kind, comparable)
86+
): MemoryObject(id, kind, module, comparable)
8287

8388
fun PythonTree.PythonTreeNode.toMemoryObject(memoryDump: MemoryDump): String {
8489
val obj = when(this) {
8590
is PythonTree.PrimitiveNode -> {
86-
ReprMemoryObject(this.id.toString(), this.type.name, this.comparable, this.repr)
91+
ReprMemoryObject(this.id.toString(), this.type.name, this.type.moduleName, this.comparable, this.repr)
8792
}
8893
is PythonTree.ListNode -> {
8994
val items = this.items.entries
9095
.sortedBy { it.key }
9196
.map { it.value.toMemoryObject(memoryDump) }
92-
ListMemoryObject(this.id.toString(), this.type.name, this.comparable, items)
97+
ListMemoryObject(this.id.toString(), this.type.name, this.type.moduleName, this.comparable, items)
9398
}
9499
is PythonTree.TupleNode -> {
95100
val items = this.items.entries
96101
.sortedBy { it.key }
97102
.map { it.value.toMemoryObject(memoryDump) }
98-
ListMemoryObject(this.id.toString(), this.type.name, this.comparable, items)
103+
ListMemoryObject(this.id.toString(), this.type.name, this.type.moduleName, this.comparable, items)
99104
}
100105
is PythonTree.SetNode -> {
101106
val items = this.items.map { it.toMemoryObject(memoryDump) }
102-
ListMemoryObject(this.id.toString(), this.type.name, this.comparable, items)
107+
ListMemoryObject(this.id.toString(), this.type.name, this.type.moduleName, this.comparable, items)
103108
}
104109
is PythonTree.DictNode -> {
105110
val items = this.items.entries
106111
.associate {
107112
it.key.toMemoryObject(memoryDump) to it.value.toMemoryObject(memoryDump)
108113
}
109-
DictMemoryObject(this.id.toString(), this.type.name, this.comparable, items)
114+
DictMemoryObject(this.id.toString(), this.type.name, this.type.moduleName, this.comparable, items)
110115
}
111116
is PythonTree.ReduceNode -> {
112117
val stateObjId = PythonTree.DictNode(this.state.entries.associate { PythonTree.PrimitiveNode(pythonStrClassId, it.key) to it.value }.toMutableMap())
@@ -116,6 +121,7 @@ fun PythonTree.PythonTreeNode.toMemoryObject(memoryDump: MemoryDump): String {
116121
ReduceMemoryObject(
117122
this.id.toString(),
118123
this.type.name,
124+
this.type.moduleName,
119125
this.comparable,
120126
this.constructor.name,
121127
argsIds.toMemoryObject(memoryDump),
@@ -137,7 +143,7 @@ fun MemoryObject.toPythonTree(memoryDump: MemoryDump): PythonTree.PythonTreeNode
137143
is ReprMemoryObject -> {
138144
PythonTree.PrimitiveNode(
139145
this.id.toLong(),
140-
PythonClassId(this.kind),
146+
PythonClassId(this.module, this.kind),
141147
this.value
142148
)
143149
}

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ import org.utbot.python.framework.api.python.util.moduleOfType
1717
const val pythonBuiltinsModuleName = "builtins"
1818

1919
class PythonClassId(
20-
name: String // includes module (like "_ast.Assign")
20+
val moduleName: String,
21+
name: String,
2122
) : ClassId(name) {
22-
override fun toString(): String = name
23-
val rootModuleName: String = this.toString().split(".")[0]
24-
override val simpleName: String = name.split(".").last()
25-
val moduleName: String
26-
get() {
27-
return moduleOfType(name) ?: pythonBuiltinsModuleName
28-
}
23+
constructor(fullName: String) : this(
24+
moduleOfType(fullName) ?: pythonBuiltinsModuleName,
25+
fullName.removePrefix(moduleOfType(fullName) ?: pythonBuiltinsModuleName).removePrefix(".")
26+
)
27+
override fun toString(): String = canonicalName
28+
val rootModuleName: String = moduleName.split(".").first()
29+
override val simpleName: String = name
30+
override val canonicalName = "$moduleName.$name"
2931
override val packageName = moduleName
30-
override val canonicalName = name
3132
}
3233

3334
open class RawPythonAnnotation(

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@ package org.utbot.python.framework.api.python.util
22

33
import org.utbot.python.framework.api.python.PythonClassId
44
import org.utbot.python.framework.api.python.NormalizedPythonAnnotation
5-
import org.utbot.python.framework.api.python.PythonBoolModel
6-
import org.utbot.python.framework.api.python.PythonListModel
7-
import org.utbot.python.framework.api.python.PythonTupleModel
8-
import org.utbot.python.framework.api.python.PythonDictModel
9-
import org.utbot.python.framework.api.python.PythonSetModel
105

116
// none annotation can be used in code only since Python 3.10
127
val pythonNoneClassId = PythonClassId("types.NoneType")

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,26 @@ import org.utbot.python.framework.api.python.util.pythonNoneClassId
1717
import org.utbot.python.framework.codegen.PythonCgLanguageAssistant
1818
import org.utbot.python.framework.codegen.model.tree.*
1919

20-
class PythonCgVariableConstructor(context_: CgContext) : CgVariableConstructor(context_) {
20+
class PythonCgVariableConstructor(cgContext: CgContext) : CgVariableConstructor(cgContext) {
2121
private val nameGenerator = CgComponents.getNameGeneratorBy(context)
2222

2323
override fun getOrCreateVariable(model: UtModel, name: String?): CgValue {
2424
val baseName = name ?: nameGenerator.nameFrom(model.classId)
2525
return valueByModel.getOrPut(model) {
2626
when (model) {
27-
is PythonBoolModel -> CgLiteral(model.classId, model.value)
28-
is PythonPrimitiveModel -> CgLiteral(model.classId, model.value)
27+
is PythonBoolModel -> {
28+
CgLiteral(model.classId, model.value)
29+
}
30+
is PythonPrimitiveModel -> {
31+
CgLiteral(model.classId, model.value)
32+
}
2933
is PythonTreeModel -> {
3034
val (value, arguments) = pythonBuildObject(model.tree)
3135
CgPythonTree(model.classId, model.tree, value, arguments)
3236
}
33-
is PythonInitObjectModel -> constructInitObjectModel(model, baseName)
37+
is PythonInitObjectModel -> {
38+
constructInitObjectModel(model, baseName)
39+
}
3440
is PythonDictModel -> CgPythonDict(model.stores.map {
3541
getOrCreateVariable(it.key) to getOrCreateVariable(
3642
it.value

0 commit comments

Comments
 (0)