-
Notifications
You must be signed in to change notification settings - Fork 45
Introduce utbot-usvm module and use it in contest #2715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
784050e
Introduce utbot-usvm
EgorkaKulikov 558506a
Use utbot-usvm in utbot-junit-contest
EgorkaKulikov a2e90a8
Move three more classes
EgorkaKulikov 7bfaa48
Little cleanup
EgorkaKulikov 379ad27
Some compilation fixes
EgorkaKulikov c03ed4b
Apply review fixes
EgorkaKulikov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
258 changes: 258 additions & 0 deletions
258
utbot-framework-api/src/main/kotlin/org/utbot/framework/utils/UtilMethodProvider.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,258 @@ | ||
| package org.utbot.framework.utils | ||
|
|
||
| import org.utbot.framework.plugin.api.BuiltinClassId | ||
| import org.utbot.framework.plugin.api.BuiltinConstructorId | ||
| import org.utbot.framework.plugin.api.BuiltinMethodId | ||
| import org.utbot.framework.plugin.api.CgClassId | ||
| import org.utbot.framework.plugin.api.ClassId | ||
| import org.utbot.framework.plugin.api.MethodId | ||
| import org.utbot.framework.plugin.api.util.arrayTypeOf | ||
| import org.utbot.framework.plugin.api.util.baseStreamClassId | ||
| import org.utbot.framework.plugin.api.util.booleanClassId | ||
| import org.utbot.framework.plugin.api.util.builtinConstructorId | ||
| import org.utbot.framework.plugin.api.util.classClassId | ||
| import org.utbot.framework.plugin.api.util.id | ||
| import org.utbot.framework.plugin.api.util.intClassId | ||
| import org.utbot.framework.plugin.api.util.objectArrayClassId | ||
| import org.utbot.framework.plugin.api.util.objectClassId | ||
| import org.utbot.framework.plugin.api.util.stringClassId | ||
| import org.utbot.framework.plugin.api.util.voidClassId | ||
| import sun.misc.Unsafe | ||
| import java.lang.invoke.MethodHandles | ||
| import java.lang.invoke.MethodType | ||
| import java.lang.reflect.Method | ||
|
|
||
| /** | ||
| * Set of ids of all possible util methods for a given class. | ||
| * | ||
| * The class may actually not have some of these methods if they | ||
| * are not required in the process of code generation (this is the case for [TestClassUtilMethodProvider]). | ||
| */ | ||
| abstract class UtilMethodProvider(val utilClassId: ClassId) { | ||
| val utilMethodIds: Set<MethodId> | ||
| get() = setOf( | ||
| getUnsafeInstanceMethodId, | ||
| createInstanceMethodId, | ||
| createArrayMethodId, | ||
| setFieldMethodId, | ||
| setStaticFieldMethodId, | ||
| getFieldValueMethodId, | ||
| getStaticFieldValueMethodId, | ||
| getEnumConstantByNameMethodId, | ||
| deepEqualsMethodId, | ||
| arraysDeepEqualsMethodId, | ||
| iterablesDeepEqualsMethodId, | ||
| streamsDeepEqualsMethodId, | ||
| mapsDeepEqualsMethodId, | ||
| hasCustomEqualsMethodId, | ||
| getArrayLengthMethodId, | ||
| consumeBaseStreamMethodId, | ||
| buildStaticLambdaMethodId, | ||
| buildLambdaMethodId, | ||
| getLookupInMethodId, | ||
| getLambdaCapturedArgumentTypesMethodId, | ||
| getLambdaCapturedArgumentValuesMethodId, | ||
| getInstantiatedMethodTypeMethodId, | ||
| getLambdaMethodMethodId, | ||
| getSingleAbstractMethodMethodId | ||
| ) | ||
|
|
||
| val getUnsafeInstanceMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getUnsafeInstance", | ||
| returnType = Unsafe::class.id, | ||
| ) | ||
|
|
||
| /** | ||
| * Method that creates instance using Unsafe | ||
| */ | ||
| val createInstanceMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "createInstance", | ||
| returnType = CgClassId(objectClassId, isNullable = true), | ||
| arguments = arrayOf(stringClassId) | ||
| ) | ||
|
|
||
| val createArrayMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "createArray", | ||
| returnType = Array<Any>::class.id, | ||
| arguments = arrayOf(stringClassId, intClassId, Array<Any>::class.id) | ||
| ) | ||
|
|
||
| val setFieldMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "setField", | ||
| returnType = voidClassId, | ||
| arguments = arrayOf(objectClassId, stringClassId, stringClassId, objectClassId) | ||
| ) | ||
|
|
||
| val setStaticFieldMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "setStaticField", | ||
| returnType = voidClassId, | ||
| arguments = arrayOf(Class::class.id, stringClassId, objectClassId) | ||
| ) | ||
|
|
||
| val getFieldValueMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getFieldValue", | ||
| returnType = objectClassId, | ||
| arguments = arrayOf(objectClassId, stringClassId, stringClassId) | ||
| ) | ||
|
|
||
| val getStaticFieldValueMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getStaticFieldValue", | ||
| returnType = objectClassId, | ||
| arguments = arrayOf(Class::class.id, stringClassId) | ||
| ) | ||
|
|
||
| val getEnumConstantByNameMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getEnumConstantByName", | ||
| returnType = objectClassId, | ||
| arguments = arrayOf(Class::class.id, stringClassId) | ||
| ) | ||
|
|
||
| val deepEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "deepEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(objectClassId, objectClassId) | ||
| ) | ||
|
|
||
| val arraysDeepEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "arraysDeepEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(objectClassId, objectClassId) | ||
| ) | ||
|
|
||
| val iterablesDeepEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "iterablesDeepEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(java.lang.Iterable::class.id, java.lang.Iterable::class.id) | ||
| ) | ||
|
|
||
| val streamsDeepEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "streamsDeepEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(java.util.stream.BaseStream::class.id, java.util.stream.BaseStream::class.id) | ||
| ) | ||
|
|
||
| val mapsDeepEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "mapsDeepEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(java.util.Map::class.id, java.util.Map::class.id) | ||
| ) | ||
|
|
||
| val hasCustomEqualsMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "hasCustomEquals", | ||
| returnType = booleanClassId, | ||
| arguments = arrayOf(Class::class.id) | ||
| ) | ||
|
|
||
| val getArrayLengthMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getArrayLength", | ||
| returnType = intClassId, | ||
| arguments = arrayOf(objectClassId) | ||
| ) | ||
|
|
||
| val consumeBaseStreamMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "consumeBaseStream", | ||
| returnType = voidClassId, | ||
| arguments = arrayOf(baseStreamClassId) | ||
| ) | ||
|
|
||
| val buildStaticLambdaMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "buildStaticLambda", | ||
| returnType = objectClassId, | ||
| arguments = arrayOf( | ||
| classClassId, | ||
| classClassId, | ||
| stringClassId, | ||
| arrayTypeOf(capturedArgumentClassId) | ||
| ) | ||
| ) | ||
|
|
||
| val buildLambdaMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "buildLambda", | ||
| returnType = objectClassId, | ||
| arguments = arrayOf( | ||
| classClassId, | ||
| classClassId, | ||
| stringClassId, | ||
| objectClassId, | ||
| arrayTypeOf(capturedArgumentClassId) | ||
| ) | ||
| ) | ||
|
|
||
| val getLookupInMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getLookupIn", | ||
| returnType = MethodHandles.Lookup::class.id, | ||
| arguments = arrayOf(classClassId) | ||
| ) | ||
|
|
||
| val getLambdaCapturedArgumentTypesMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getLambdaCapturedArgumentTypes", | ||
| returnType = arrayTypeOf(classClassId), | ||
| arguments = arrayOf(arrayTypeOf(capturedArgumentClassId)) | ||
| ) | ||
|
|
||
| val getLambdaCapturedArgumentValuesMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getLambdaCapturedArgumentValues", | ||
| returnType = objectArrayClassId, | ||
| arguments = arrayOf(arrayTypeOf(capturedArgumentClassId)) | ||
| ) | ||
|
|
||
| val getInstantiatedMethodTypeMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getInstantiatedMethodType", | ||
| returnType = MethodType::class.id, | ||
| arguments = arrayOf(Method::class.id, arrayTypeOf(classClassId)) | ||
| ) | ||
|
|
||
| val getLambdaMethodMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getLambdaMethod", | ||
| returnType = Method::class.id, | ||
| arguments = arrayOf(classClassId, stringClassId) | ||
| ) | ||
|
|
||
| val getSingleAbstractMethodMethodId: MethodId | ||
| get() = utilClassId.utilMethodId( | ||
| name = "getSingleAbstractMethod", | ||
| returnType = java.lang.reflect.Method::class.id, | ||
| arguments = arrayOf(classClassId) | ||
| ) | ||
|
|
||
| val capturedArgumentClassId: BuiltinClassId | ||
| get() = BuiltinClassId( | ||
| canonicalName = "${utilClassId.name}.CapturedArgument", | ||
| simpleName = "CapturedArgument" | ||
| ) | ||
|
|
||
| val capturedArgumentConstructorId: BuiltinConstructorId | ||
| get() = builtinConstructorId(capturedArgumentClassId, classClassId, objectClassId) | ||
| } | ||
|
|
||
| internal fun ClassId.utilMethodId( | ||
| name: String, | ||
| returnType: ClassId, | ||
| vararg arguments: ClassId, | ||
| // usually util methods are static, so this argument is true by default | ||
| isStatic: Boolean = true | ||
| ): MethodId = | ||
| BuiltinMethodId(this, name, returnType, arguments.toList(), isStatic = isStatic) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.