Skip to content

Commit

Permalink
new generators
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullinAM committed Jun 3, 2024
1 parent f01199d commit ac5f977
Show file tree
Hide file tree
Showing 25 changed files with 471 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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..<tail) {
val element = elements[i] ?: descriptor { default(elements.elementType) }
val elementAS = fallback.generate(element, generationDepth)
actionSequence += MethodCall(addMethod, listOf(elementAS))
}
} else if (tail - head > 0) {
for (i in head..<tail) {
val elementAS = fallback.generate(descriptor { `null` }, generationDepth)
actionSequence += MethodCall(addMethod, listOf(elementAS))
}
}

actionSequence
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.arrayListClass
import org.vorpal.research.kfg.type.objectType

class ArrayListGenerator(val fallback: Generator) : Generator {
override val context: GeneratorContext
get() = fallback.context

private val kfgArrayList = context.cm.arrayListClass
private val kexArrayList = kfgArrayList.kexType
private val kfgObjectType = context.cm.type.objectType

override fun supports(descriptor: Descriptor): Boolean = descriptor.type == kexArrayList

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 elementData = descriptor["elementData" to kfgObjectType.kexType.asArray()] as? ArrayDescriptor
val size = (descriptor["size" to KexInt] as? ConstantDescriptor.Int)?.value ?: elementData?.length ?: 0
actionSequence += DefaultConstructorCall(kfgArrayList)

val addMethod = kfgArrayList.getMethod("add", cm.type.boolType, kfgObjectType)
if (elementData != null) {
for (i in 0 until size) {
val element = elementData[i] ?: descriptor { default(elementData.elementType) }
val elementAS = fallback.generate(element, generationDepth)
actionSequence += MethodCall(addMethod, listOf(elementAS))
}
} else if (size > 0) {
for (i in 0 until size) {
val elementAS = fallback.generate(descriptor { `null` }, generationDepth)
actionSequence += MethodCall(addMethod, listOf(elementAS))
}
}

actionSequence
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
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
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

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
Loading

0 comments on commit ac5f977

Please sign in to comment.