From ac5f977e79b6a9c65d14026272598d00575c8601 Mon Sep 17 00:00:00 2001 From: Azat Abdullin Date: Mon, 3 Jun 2024 18:37:21 +0200 Subject: [PATCH] new generators --- .../concolic/InstructionConcolicChecker.kt | 2 +- .../generator/ActionSequenceGenerator.kt | 8 ++ .../generator/CollectionGenerator.kt | 66 --------------- .../generator/ConcolicSequenceGenerator.kt | 7 ++ .../{ => kexrt}/KexArrayDequeGenerator.kt | 4 +- .../{ => kexrt}/KexArrayListGenerator.kt | 4 +- .../{ => kexrt}/KexHashMapGenerator.kt | 4 +- .../{ => kexrt}/KexHashSetGenerator.kt | 4 +- .../{ => kexrt}/KexLinkedListGenerator.kt | 4 +- .../generator/{ => kexrt}/KexRtGenerator.kt | 4 +- .../{ => kexrt}/KexStringBuilderGenerator.kt | 4 +- .../{ => kexrt}/KexWrapperClassGenerator.kt | 4 +- .../generator/rt/ArrayDequeGenerator.kt | 58 +++++++++++++ .../generator/rt/ArrayListGenerator.kt | 57 +++++++++++++ .../generator/{ => rt}/CharsetGenerator.kt | 4 +- .../generator/{ => rt}/ClassGenerator.kt | 3 +- .../generator/rt/CollectionGenerator.kt | 28 +++++++ .../generator/{ => rt}/FieldGenerator.kt | 4 +- .../generator/rt/HashMapGenerator.kt | 70 ++++++++++++++++ .../generator/rt/HashSetGenerator.kt | 81 +++++++++++++++++++ .../generator/rt/LinkedListGenerator.kt | 58 +++++++++++++ .../generator/{ => rt}/StringGenerator.kt | 4 +- .../UnmodifiableCollectionGenerator.kt | 3 +- .../generator/rt/WrapperClassGenerator.kt | 61 ++++++++++++++ .../research/kex/test/javadebug/JavaTest.java | 45 ++--------- 25 files changed, 471 insertions(+), 120 deletions(-) delete mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CollectionGenerator.kt rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexArrayDequeGenerator.kt (92%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexArrayListGenerator.kt (96%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexHashMapGenerator.kt (98%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexHashSetGenerator.kt (94%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexLinkedListGenerator.kt (96%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexRtGenerator.kt (87%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexStringBuilderGenerator.kt (93%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => kexrt}/KexWrapperClassGenerator.kt (94%) create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ArrayDequeGenerator.kt create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ArrayListGenerator.kt rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => rt}/CharsetGenerator.kt (92%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => rt}/ClassGenerator.kt (97%) create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CollectionGenerator.kt rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => rt}/FieldGenerator.kt (95%) create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashMapGenerator.kt create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashSetGenerator.kt create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/LinkedListGenerator.kt rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => rt}/StringGenerator.kt (92%) rename kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/{ => rt}/UnmodifiableCollectionGenerator.kt (95%) create mode 100644 kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/WrapperClassGenerator.kt diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/asm/analysis/concolic/InstructionConcolicChecker.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/asm/analysis/concolic/InstructionConcolicChecker.kt index 35e556bd5..3cebd2b61 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/asm/analysis/concolic/InstructionConcolicChecker.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/asm/analysis/concolic/InstructionConcolicChecker.kt @@ -161,7 +161,7 @@ class InstructionConcolicChecker( val testWithAssertionsGenerator = UnsafeGenerator( ctx, method, testNameGenerator.generateName(method, parameters) ) - // TODO: handle kex-rt mapped classes correctly + val finalInfoDescriptors = extractFinalParameters(result, method) testWithAssertionsGenerator.generate(parameters, finalInfoDescriptors) testWithAssertions = testWithAssertionsGenerator.emit() diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ActionSequenceGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ActionSequenceGenerator.kt index dee6e09af..5ec124f51 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ActionSequenceGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ActionSequenceGenerator.kt @@ -6,6 +6,13 @@ import org.vorpal.research.kex.config.kexConfig import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.UnknownSequence +import org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt.KexRtGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.CharsetGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.ClassGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.CollectionGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.FieldGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.StringGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.UnmodifiableCollectionGenerator import org.vorpal.research.kthelper.KtException import org.vorpal.research.kthelper.assert.unreachable import org.vorpal.research.kthelper.logging.debug @@ -34,6 +41,7 @@ class ActionSequenceGenerator(override val context: GeneratorContext) : Generato typeGenerators += EnumGenerator(this) typeGenerators += KtObjectGenerator(this) typeGenerators += InnerClassGenerator(this) + typeGenerators += CollectionGenerator(this) typeGenerators += KexRtGenerator(this) typeGenerators += UnmodifiableCollectionGenerator(this) typeGenerators += ReanimatingCollectionGenerator(this) diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CollectionGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CollectionGenerator.kt deleted file mode 100644 index ce47f5370..000000000 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CollectionGenerator.kt +++ /dev/null @@ -1,66 +0,0 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator - -import org.vorpal.research.kex.descriptor.Descriptor -import org.vorpal.research.kex.descriptor.ObjectDescriptor -import org.vorpal.research.kex.ktype.KexClass -import org.vorpal.research.kex.reanimator.actionsequence.ActionList -import org.vorpal.research.kex.reanimator.actionsequence.CodeAction -import org.vorpal.research.kex.util.isSubtypeOfCached -import org.vorpal.research.kfg.collectionClass -import org.vorpal.research.kfg.ir.Class - -// difference from any generator -- ignore all external and recursive ctors -class CollectionGenerator(fallback: Generator) : AnyGenerator(fallback) { - companion object { - private val ignoredMethods = setOf( - "trimToSize", - "addAll", - "size", - "ensureCapacity", - "isEmpty", - "contains", - "indexOf", - "lastIndexOf", - "clone", - "toArray" - ) - } - - override fun supports(descriptor: Descriptor): Boolean { - val type = descriptor.type - val klass = type as? KexClass ?: return false - val tf = context.types - return klass.getKfgType(tf).isSubtypeOfCached(tf.cm.collectionClass.asType) - } - - override fun checkCtors( - sequence: ActionList, - klass: Class, - current: ObjectDescriptor, - currentStack: List, - fallbacks: MutableSet>, - generationDepth: Int - ): Boolean = internalCheckConstructors( - sequence, klass, current, currentStack, fallbacks, generationDepth - ) { with(context) { klass.nonRecursiveCtors } } - - override fun applyMethods( - sequence: ActionList, - klass: Class, - current: ObjectDescriptor, - currentStack: List, - searchDepth: Int, - generationDepth: Int - ): List> = internalApplyMethods( - current, currentStack, searchDepth, generationDepth - ) { - with(context) { - val collectionKlass = cm.collectionClass.asType - klass.accessibleMethods - .filter { it.name !in ignoredMethods } - .filterNotTo(mutableSetOf()) { - it.argTypes.any { arg -> arg.isSubtypeOfCached(collectionKlass) } - } - } - } -} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ConcolicSequenceGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ConcolicSequenceGenerator.kt index 10909b393..da9a4196b 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ConcolicSequenceGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ConcolicSequenceGenerator.kt @@ -11,6 +11,12 @@ import org.vorpal.research.kex.reanimator.actionsequence.ReflectionCall import org.vorpal.research.kex.reanimator.actionsequence.ReflectionGetField import org.vorpal.research.kex.reanimator.actionsequence.ReflectionGetStaticField import org.vorpal.research.kex.reanimator.actionsequence.ReflectionList +import org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt.KexRtGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.CharsetGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.ClassGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.CollectionGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.FieldGenerator +import org.vorpal.research.kex.reanimator.actionsequence.generator.rt.StringGenerator import org.vorpal.research.kex.util.getFieldSafe import org.vorpal.research.kfg.ir.Field import org.vorpal.research.kthelper.assert.unreachable @@ -32,6 +38,7 @@ class ConcolicSequenceGenerator(override val context: GeneratorContext) : Genera typeGenerators += MethodGenerator(this) typeGenerators += FieldGenerator(this) typeGenerators += ReflectionEnumGenerator(this) + typeGenerators += CollectionGenerator(this) typeGenerators += KexRtGenerator(this) typeGenerators += MockGenerator(this) typeGenerators += UnknownGenerator(this) diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayDequeGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayDequeGenerator.kt similarity index 92% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayDequeGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayDequeGenerator.kt index dac8b3baa..3012f6b3c 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayDequeGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayDequeGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor @@ -8,6 +8,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.ConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kex.util.getCtor import org.vorpal.research.kfg.arrayDequeClass import org.vorpal.research.kfg.type.arrayListType diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayListGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayListGenerator.kt similarity index 96% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayListGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayListGenerator.kt index 4b7a05211..b889ec095 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexArrayListGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexArrayListGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.ConstantDescriptor @@ -15,6 +15,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.ExternalMethodCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.arrayListClass import org.vorpal.research.kfg.ir.ConcreteClass import org.vorpal.research.kfg.type.ClassType diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashMapGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashMapGenerator.kt similarity index 98% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashMapGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashMapGenerator.kt index e8ea3150d..70d63c9d3 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashMapGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashMapGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.Descriptor @@ -13,6 +13,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.ExternalMethodCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.collectionClass import org.vorpal.research.kfg.ir.ConcreteClass import org.vorpal.research.kfg.setClass diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashSetGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashSetGenerator.kt similarity index 94% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashSetGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashSetGenerator.kt index a6ea01cdb..b47da2476 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexHashSetGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexHashSetGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.Descriptor @@ -11,6 +11,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.hashMapClass import org.vorpal.research.kfg.hashSetClass import org.vorpal.research.kfg.linkedHashSetClass diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexLinkedListGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexLinkedListGenerator.kt similarity index 96% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexLinkedListGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexLinkedListGenerator.kt index f8576a793..247a3ebe0 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexLinkedListGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexLinkedListGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.ConstantDescriptor @@ -15,6 +15,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.ExternalMethodCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.arrayListClass import org.vorpal.research.kfg.ir.ConcreteClass import org.vorpal.research.kfg.linkedListClass diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexRtGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexRtGenerator.kt similarity index 87% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexRtGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexRtGenerator.kt index 95a2b74f5..002a281e0 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexRtGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexRtGenerator.kt @@ -1,7 +1,9 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext class KexRtGenerator(val fallback: Generator) : Generator { override val context: GeneratorContext diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexStringBuilderGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexStringBuilderGenerator.kt similarity index 93% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexStringBuilderGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexStringBuilderGenerator.kt index 5063d8669..be2136d5d 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexStringBuilderGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexStringBuilderGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.Descriptor @@ -11,6 +11,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.stringBufferClass import org.vorpal.research.kfg.stringBuilderClass import org.vorpal.research.kfg.type.ClassType diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexWrapperClassGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexWrapperClassGenerator.kt similarity index 94% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexWrapperClassGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexWrapperClassGenerator.kt index e6e277f57..6371360c0 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/KexWrapperClassGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/kexrt/KexWrapperClassGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.kexrt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor @@ -9,6 +9,8 @@ import org.vorpal.research.kex.ktype.kexType import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.ConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kex.util.getCtor import org.vorpal.research.kex.util.getPrimitive import org.vorpal.research.kfg.boolWrapper diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ArrayDequeGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ArrayDequeGenerator.kt new file mode 100644 index 000000000..259437e15 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ArrayDequeGenerator.kt @@ -0,0 +1,58 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.ArrayDescriptor +import org.vorpal.research.kex.descriptor.ConstantDescriptor +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.descriptor.ObjectDescriptor +import org.vorpal.research.kex.descriptor.descriptor +import org.vorpal.research.kex.ktype.KexInt +import org.vorpal.research.kex.ktype.asArray +import org.vorpal.research.kex.ktype.kexType +import org.vorpal.research.kex.reanimator.actionsequence.ActionList +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext +import org.vorpal.research.kfg.arrayDequeClass +import org.vorpal.research.kfg.type.objectType + +class ArrayDequeGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + + private val kfgArrayDeque = context.cm.arrayDequeClass + private val kexArrayDeque = kfgArrayDeque.kexType + private val kfgObjectType = context.cm.type.objectType + + override fun supports(descriptor: Descriptor): Boolean = descriptor.type == kexArrayDeque + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + descriptor as ObjectDescriptor + + val name = "${descriptor.term}" + val actionSequence = ActionList(name) + saveToCache(descriptor, actionSequence) + + val elements = descriptor["elements" to kfgObjectType.kexType.asArray()] as? ArrayDescriptor + val head = (descriptor["head" to KexInt] as? ConstantDescriptor.Int)?.value ?: 0 + val tail = (descriptor["tail" to KexInt] as? ConstantDescriptor.Int)?.value ?: elements?.length ?: 0 + actionSequence += DefaultConstructorCall(kfgArrayDeque) + + val addMethod = kfgArrayDeque.getMethod("add", cm.type.boolType, kfgObjectType) + if (elements != null) { + for (i in head.. 0) { + for (i in head.. 0) { + for (i in 0 until size) { + val elementAS = fallback.generate(descriptor { `null` }, generationDepth) + actionSequence += MethodCall(addMethod, listOf(elementAS)) + } + } + + actionSequence + } +} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CharsetGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CharsetGenerator.kt similarity index 92% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CharsetGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CharsetGenerator.kt index ca46a6df3..69484f940 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/CharsetGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CharsetGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor @@ -6,6 +6,8 @@ import org.vorpal.research.kex.ktype.KexString import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.StaticFieldGetter +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kfg.type.SystemTypeNames import org.vorpal.research.kthelper.logging.log diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ClassGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ClassGenerator.kt similarity index 97% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ClassGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ClassGenerator.kt index 441271b80..232c0b269 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/ClassGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/ClassGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt import org.vorpal.research.kex.descriptor.ConstantDescriptor import org.vorpal.research.kex.descriptor.Descriptor @@ -11,6 +11,7 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.ArrayClassConstantGetter import org.vorpal.research.kex.reanimator.actionsequence.ClassConstantGetter import org.vorpal.research.kex.reanimator.actionsequence.ExternalConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator import org.vorpal.research.kfg.classClass import org.vorpal.research.kfg.type.SystemTypeNames import org.vorpal.research.kfg.type.classType diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CollectionGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CollectionGenerator.kt new file mode 100644 index 000000000..3e3674f91 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/CollectionGenerator.kt @@ -0,0 +1,28 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext + +class CollectionGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + + private val generators = setOf( + ArrayListGenerator(this), + ArrayDequeGenerator(this), + LinkedListGenerator(this), + HashMapGenerator(this), + HashSetGenerator(this), + WrapperClassGenerator(this) + ) + + override fun supports(descriptor: Descriptor): Boolean = generators.any { it.supports(descriptor) } + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + getFromCache(descriptor)?.let { return it } + val generator = generators.firstOrNull { it.supports(descriptor) } ?: fallback + generator.generate(descriptor, generationDepth) + } +} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/FieldGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/FieldGenerator.kt similarity index 95% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/FieldGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/FieldGenerator.kt index 55a6cf4cd..046756af5 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/FieldGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/FieldGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor @@ -11,6 +11,8 @@ import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.ExternalMethodCall import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kex.util.asmString import org.vorpal.research.kfg.ir.Class import org.vorpal.research.kfg.type.SystemTypeNames diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashMapGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashMapGenerator.kt new file mode 100644 index 000000000..24cba4595 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashMapGenerator.kt @@ -0,0 +1,70 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.ArrayDescriptor +import org.vorpal.research.kex.descriptor.ConstantDescriptor +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.descriptor.ObjectDescriptor +import org.vorpal.research.kex.descriptor.descriptor +import org.vorpal.research.kex.ktype.kexType +import org.vorpal.research.kex.reanimator.actionsequence.ActionList +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext +import org.vorpal.research.kfg.hashMapClass +import org.vorpal.research.kfg.linkedHashMapClass +import org.vorpal.research.kfg.objectClass +import org.vorpal.research.kfg.type.SystemTypeNames +import org.vorpal.research.kthelper.assert.unreachable +import org.vorpal.research.kthelper.logging.log + +class HashMapGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + + private val objectClass = context.cm.objectClass + private val hashMapClass = context.cm.hashMapClass + private val linkedHashMapClass = context.cm.linkedHashMapClass + private val kexObjectClass = objectClass.kexType + private val kexHashMapClass = hashMapClass.kexType + private val kexLinkedHashMapClass = linkedHashMapClass.kexType + private val kexHashMapNode = context.cm[SystemTypeNames.hashMapClass + "\$Node"].kexType + + override fun supports(descriptor: Descriptor): Boolean = + descriptor.type == kexHashMapClass || descriptor.type == kexLinkedHashMapClass + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + descriptor as ObjectDescriptor + + val name = "${descriptor.term}" + val actionSequence = ActionList(name) + + val table = descriptor["table" to kexHashMapNode] as? ArrayDescriptor + actionSequence += when (descriptor.type) { + kexHashMapClass -> DefaultConstructorCall(hashMapClass) + kexLinkedHashMapClass -> DefaultConstructorCall(linkedHashMapClass) + else -> unreachable { log.error("Unknown descriptor type: $descriptor") } + } + + val addMethod = hashMapClass.getMethod("put", objectClass.asType, objectClass.asType, objectClass.asType) + if (table != null) { + for (i in 0 until table.length) { + var element = table[i] as? ObjectDescriptor + while (element != null) { + val key = element["key" to kexObjectClass] + val value = element["value" to kexObjectClass] ?: descriptor { `null` } + if (key == null || key is ConstantDescriptor.Null) continue + + val keyAS = fallback.generate(key, generationDepth) + val valueAS = fallback.generate(value, generationDepth) + actionSequence += MethodCall(addMethod, listOf(keyAS, valueAS)) + + element = element["next" to kexHashMapNode] as? ObjectDescriptor + } + } + } + + actionSequence + } +} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashSetGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashSetGenerator.kt new file mode 100644 index 000000000..965bd96f4 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/HashSetGenerator.kt @@ -0,0 +1,81 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.descriptor.ObjectDescriptor +import org.vorpal.research.kex.ktype.KexNull +import org.vorpal.research.kex.ktype.kexType +import org.vorpal.research.kex.reanimator.actionsequence.ActionList +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.ConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.ExternalMethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext +import org.vorpal.research.kex.state.term.term +import org.vorpal.research.kex.util.getCtor +import org.vorpal.research.kfg.collectionClass +import org.vorpal.research.kfg.hashMapClass +import org.vorpal.research.kfg.hashSetClass +import org.vorpal.research.kfg.linkedHashSetClass +import org.vorpal.research.kfg.mapClass +import org.vorpal.research.kfg.setClass +import org.vorpal.research.kthelper.assert.unreachable +import org.vorpal.research.kthelper.logging.log + +class HashSetGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + + private val hashSetClass = context.cm.hashSetClass + private val linkedHashSetClass = context.cm.linkedHashSetClass + private val hashMapClass = context.cm.hashMapClass + private val kexHashMapClass = hashMapClass.kexType + private val kexHashSetClass = hashSetClass.kexType + private val kexLinkedHashSetClass = linkedHashSetClass.kexType + + override fun supports(descriptor: Descriptor): Boolean = + descriptor.type == kexHashSetClass || descriptor.type == kexLinkedHashSetClass + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + descriptor as ObjectDescriptor + + val name = "${descriptor.term}" + val actionSequence = ActionList(name) + + when (val table = descriptor["map" to kexHashMapClass] as? ObjectDescriptor) { + null -> { + actionSequence += when (descriptor.type) { + kexHashSetClass -> DefaultConstructorCall(hashSetClass) + kexLinkedHashSetClass -> DefaultConstructorCall(linkedHashSetClass) + else -> unreachable { log.error("Unknown descriptor type: $descriptor") } + } + + } + else -> { + val mapAS = fallback.generate(table, generationDepth) + val keySet = ActionList(term { generate(KexNull()) }.name) + keySet += ExternalMethodCall( + context.cm.mapClass.getMethod("keySet", context.cm.setClass.asType), + mapAS, + emptyList() + ) + + actionSequence += when (descriptor.type) { + kexHashSetClass -> ConstructorCall( + hashSetClass.getCtor(context.cm.collectionClass.asType), + listOf(keySet) + ) + + kexLinkedHashSetClass -> ConstructorCall( + linkedHashSetClass.getCtor(context.cm.collectionClass.asType), + listOf(keySet) + ) + + else -> unreachable { log.error("Unknown descriptor type: $descriptor") } + } + } + } + + actionSequence + } +} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/LinkedListGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/LinkedListGenerator.kt new file mode 100644 index 000000000..a981261c7 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/LinkedListGenerator.kt @@ -0,0 +1,58 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.ConstantDescriptor +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.descriptor.ObjectDescriptor +import org.vorpal.research.kex.descriptor.descriptor +import org.vorpal.research.kex.ktype.KexInt +import org.vorpal.research.kex.ktype.kexType +import org.vorpal.research.kex.reanimator.actionsequence.ActionList +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.DefaultConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.MethodCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext +import org.vorpal.research.kfg.linkedListClass +import org.vorpal.research.kfg.type.objectType + +class LinkedListGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + + private val kfgLinkedList = context.cm.linkedListClass + private val kexLinkedList = kfgLinkedList.kexType + private val kexLinkedListNode = context.cm["${kfgLinkedList.fullName}\$Node"].kexType + private val kfgObjectType = context.cm.type.objectType + + override fun supports(descriptor: Descriptor): Boolean = descriptor.type == kexLinkedList + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + descriptor as ObjectDescriptor + + val name = "${descriptor.term}" + val actionSequence = ActionList(name) + saveToCache(descriptor, actionSequence) + + var node = descriptor["first" to kexLinkedListNode] as? ObjectDescriptor + var size = (descriptor["size" to KexInt] as? ConstantDescriptor.Int)?.value ?: 0 + val addMethod = kfgLinkedList.getMethod("add", cm.type.boolType, kfgObjectType) + actionSequence += DefaultConstructorCall(kfgLinkedList) + + while (node != null) { + val element = node["item" to kfgObjectType.kexType] ?: descriptor { `null` } + val elementAS = fallback.generate(element, generationDepth) + actionSequence += MethodCall(addMethod, listOf(elementAS)) + + node = node["next" to kexLinkedListNode] as? ObjectDescriptor + --size + } + + while (size > 0) { + val elementAS = fallback.generate(descriptor { `null` }, generationDepth) + actionSequence += MethodCall(addMethod, listOf(elementAS)) + --size + } + + actionSequence + } +} diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/StringGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/StringGenerator.kt similarity index 92% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/StringGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/StringGenerator.kt index 2e25e98f4..edca71115 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/StringGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/StringGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt import org.vorpal.research.kex.descriptor.ArrayDescriptor import org.vorpal.research.kex.descriptor.ConstantDescriptor @@ -6,6 +6,8 @@ import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.StringValue +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext import org.vorpal.research.kex.util.StringInfoContext import org.vorpal.research.kfg.type.SystemTypeNames import org.vorpal.research.kthelper.assert.unreachable diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/UnmodifiableCollectionGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/UnmodifiableCollectionGenerator.kt similarity index 95% rename from kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/UnmodifiableCollectionGenerator.kt rename to kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/UnmodifiableCollectionGenerator.kt index a6ab479ac..a1f93a185 100644 --- a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/UnmodifiableCollectionGenerator.kt +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/UnmodifiableCollectionGenerator.kt @@ -1,4 +1,4 @@ -package org.vorpal.research.kex.reanimator.actionsequence.generator +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt import org.vorpal.research.kex.descriptor.Descriptor import org.vorpal.research.kex.descriptor.ObjectDescriptor @@ -8,6 +8,7 @@ import org.vorpal.research.kex.ktype.kexType import org.vorpal.research.kex.reanimator.actionsequence.ActionList import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence import org.vorpal.research.kex.reanimator.actionsequence.ExternalConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator import org.vorpal.research.kex.util.dekapitalize import org.vorpal.research.kfg.collectionClass import org.vorpal.research.kfg.type.SystemTypeNames diff --git a/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/WrapperClassGenerator.kt b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/WrapperClassGenerator.kt new file mode 100644 index 000000000..8e63b90d4 --- /dev/null +++ b/kex-runner/src/main/kotlin/org/vorpal/research/kex/reanimator/actionsequence/generator/rt/WrapperClassGenerator.kt @@ -0,0 +1,61 @@ +package org.vorpal.research.kex.reanimator.actionsequence.generator.rt + +import org.vorpal.research.kex.descriptor.Descriptor +import org.vorpal.research.kex.descriptor.ObjectDescriptor +import org.vorpal.research.kex.ktype.kexType +import org.vorpal.research.kex.reanimator.actionsequence.ActionList +import org.vorpal.research.kex.reanimator.actionsequence.ActionSequence +import org.vorpal.research.kex.reanimator.actionsequence.ConstructorCall +import org.vorpal.research.kex.reanimator.actionsequence.generator.Generator +import org.vorpal.research.kex.reanimator.actionsequence.generator.GeneratorContext +import org.vorpal.research.kex.util.getCtor +import org.vorpal.research.kex.util.getPrimitive +import org.vorpal.research.kfg.boolWrapper +import org.vorpal.research.kfg.byteWrapper +import org.vorpal.research.kfg.charWrapper +import org.vorpal.research.kfg.doubleWrapper +import org.vorpal.research.kfg.floatWrapper +import org.vorpal.research.kfg.intWrapper +import org.vorpal.research.kfg.longWrapper +import org.vorpal.research.kfg.shortWrapper +import org.vorpal.research.kfg.type.ClassType + +class WrapperClassGenerator(val fallback: Generator) : Generator { + override val context: GeneratorContext + get() = fallback.context + private val supportedTypes = setOf( + context.cm.boolWrapper.kexType, + context.cm.byteWrapper.kexType, + context.cm.charWrapper.kexType, + context.cm.shortWrapper.kexType, + context.cm.intWrapper.kexType, + context.cm.longWrapper.kexType, + context.cm.floatWrapper.kexType, + context.cm.doubleWrapper.kexType + ) + + override fun supports(descriptor: Descriptor): Boolean = + descriptor.type in supportedTypes && descriptor is ObjectDescriptor + + override fun generate(descriptor: Descriptor, generationDepth: Int): ActionSequence = with(context) { + descriptor as ObjectDescriptor + + val name = "${descriptor.term}" + val actionSequence = ActionList(name) + saveToCache(descriptor, actionSequence) + + val descriptorKfgType = descriptor.type.getKfgType(types) as ClassType + val baseKfgType = types.getPrimitive(descriptorKfgType) + val baseType = baseKfgType.kexType + + val valueDesc = when { + "value" to baseType in descriptor.fields -> descriptor["value" to baseType]!! + else -> org.vorpal.research.kex.descriptor.descriptor { default(baseType) } + } + val constructor = descriptorKfgType.klass.getCtor(baseKfgType) + val valueAS = fallback.generate(valueDesc, generationDepth) + actionSequence += ConstructorCall(constructor, listOf(valueAS)) + + actionSequence + } +} diff --git a/kex-test/src/main/kotlin/org/vorpal/research/kex/test/javadebug/JavaTest.java b/kex-test/src/main/kotlin/org/vorpal/research/kex/test/javadebug/JavaTest.java index 29215ff6b..a91cdc232 100644 --- a/kex-test/src/main/kotlin/org/vorpal/research/kex/test/javadebug/JavaTest.java +++ b/kex-test/src/main/kotlin/org/vorpal/research/kex/test/javadebug/JavaTest.java @@ -1,49 +1,14 @@ package org.vorpal.research.kex.test.javadebug; -import org.vorpal.research.kex.test.concolic.Point; +import java.util.HashMap; @SuppressWarnings("ALL") public class JavaTest { - public int foo(Point a, Point b) { - int ax = a.getX(); - int bx = b.getX(); - int mx = Math.max(ax, bx); - - int ay = a.getY(); - int by = b.getY(); - int my = Math.min(ay, by); - int res; - if (mx < my) { - System.out.println("success"); - res = mx - my; - } else if (mx > my) { - System.out.println("fail"); - res = my - mx; - } else { - throw new IllegalArgumentException(); - } - return res; - } - -// public int testWrapper(ArrayList b) { -// if (b.get(0) < 0) { -// throw new IllegalArgumentException(); -// } -// return b.size(); -// } - - public boolean testFoo(boolean b) { - if (b) { - foo(new Point(100, 100), new Point(0, 0)); - return false; - } else { - try { - foo(new Point(0, 0), new Point(0, 0)); - } catch (IllegalArgumentException e) { - System.err.println("asdsad"); - } - return true; + public int foo(HashMap list) { + if (list.size() == 1) { + System.out.println("a"); } + return 0; } }