From 556fa9594b8f62d9c776e9cb8c2f54ebea213c5a Mon Sep 17 00:00:00 2001 From: Ekaterina Date: Fri, 20 Dec 2024 20:07:15 +0300 Subject: [PATCH] Fixed Python build --- .../annotations/CPythonFunctionProcessor.kt | 7 ++----- .../annotations/SymbolicMethodProcessor.kt | 8 +++----- .../main/kotlin/org/usvm/annotations/Utils.kt | 5 +++++ .../org/usvm/interpreter/CPythonAdapter.java | 20 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/CPythonFunctionProcessor.kt b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/CPythonFunctionProcessor.kt index b47df40ea6..cabd8d8380 100644 --- a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/CPythonFunctionProcessor.kt +++ b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/CPythonFunctionProcessor.kt @@ -52,9 +52,7 @@ class CPythonFunctionProcessor : AbstractProcessor() { val firstType = executable.parameters .first() .asType() - .toString() - .split(".") - .last() + .getTypeName() require(firstType == "ConcolicRunContext") { "First argument of function annotated with CPythonFunction must be ConcolicRunContext" } @@ -74,8 +72,7 @@ class CPythonFunctionProcessor : AbstractProcessor() { require(returnTypeName == "void" || returnTypeName == "SymbolForCPython") { "Return type must be void or SymbolForCPython, not $returnTypeName" } - val returnType = convertJavaType(executable.returnType) - when (returnType) { + when (val returnType = convertJavaType(executable.returnType)) { JavaType.JObject -> { val descr = ArgumentDescription( CType.PyObject, diff --git a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/SymbolicMethodProcessor.kt b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/SymbolicMethodProcessor.kt index 8bd07bfe89..c2b1bfeae1 100644 --- a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/SymbolicMethodProcessor.kt +++ b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/SymbolicMethodProcessor.kt @@ -51,15 +51,13 @@ class SymbolicMethodProcessor : AbstractProcessor() { val arg0 = element.parameters .first() .asType() - .toString() - .split(".") - .last() + .getTypeName() require(arg0 == "ConcolicRunContext") { formatMsg } - val arg1 = element.parameters[1].asType().toString().split(".").last() + val arg1 = element.parameters[1].asType().getTypeName() require(arg1 == "SymbolForCPython") { formatMsg } val arg2 = element.parameters[2].asType() require(arg2 is ArrayType) { formatMsg } - val arg2Elem = arg2.componentType.toString().split(".").last() + val arg2Elem = arg2.componentType.getTypeName() require(arg2Elem == "SymbolForCPython") { formatMsg } val elementAnnotation = element.getAnnotation(SymbolicMethod::class.java)!! require(elementAnnotation.id !in definedIds) { diff --git a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/Utils.kt b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/Utils.kt index daa213c9ae..10f911a134 100644 --- a/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/Utils.kt +++ b/usvm-python/usvm-python-annotations/src/main/kotlin/org/usvm/annotations/Utils.kt @@ -2,6 +2,8 @@ package org.usvm.annotations import java.io.File import javax.annotation.processing.ProcessingEnvironment +import javax.lang.model.element.VariableElement +import javax.lang.model.type.TypeMirror fun getHeaderPath(processingEnv: ProcessingEnvironment): File { val headerPath = processingEnv.options["headerPath"] ?: error("Header path not specified") @@ -9,3 +11,6 @@ fun getHeaderPath(processingEnv: ProcessingEnvironment): File { result.mkdirs() return result } + +fun TypeMirror.getTypeName(): String = + toString().split('.').last().split(' ').last() diff --git a/usvm-python/usvm-python-main/src/main/java/org/usvm/interpreter/CPythonAdapter.java b/usvm-python/usvm-python-main/src/main/java/org/usvm/interpreter/CPythonAdapter.java index 1ebc097479..34501f1b92 100644 --- a/usvm-python/usvm-python-main/src/main/java/org/usvm/interpreter/CPythonAdapter.java +++ b/usvm-python/usvm-python-main/src/main/java/org/usvm/interpreter/CPythonAdapter.java @@ -126,7 +126,7 @@ public class CPythonAdapter { argCTypes = {CType.PyFrameObject}, argConverters = {ObjectConverter.FrameConverter} ) - public static void handlerInstruction(@NotNull ConcolicRunContext context, long frameRef) { + public static void handlerInstruction(ConcolicRunContext context, long frameRef) { if (pythonExceptionOccurred() != 0) return; context.curOperation = null; @@ -1255,28 +1255,28 @@ public static SymbolForCPython handlerCreateEmptyObject(ConcolicRunContext conte @CPythonAdapterJavaMethod(cName = "symbolic_method_int") @SymbolicMethod(id = SymbolicMethodId.Int) - public static SymbolForCPython symbolicMethodInt(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodInt(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { assert(self == null); return withTracing(context, new SymbolicMethodParameters("int", null, args), () -> symbolicMethodIntKt(context, args)); } @CPythonAdapterJavaMethod(cName = "symbolic_method_float") @SymbolicMethod(id = SymbolicMethodId.Float) - public static SymbolForCPython symbolicMethodFloat(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodFloat(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { assert(self == null); return withTracing(context, new SymbolicMethodParameters("float", null, args), () -> symbolicMethodFloatKt(context, args)); } @CPythonAdapterJavaMethod(cName = "symbolic_method_enumerate") @SymbolicMethod(id = SymbolicMethodId.Enumerate) - public static SymbolForCPython symbolicMethodEnumerate(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodEnumerate(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { assert(self == null); return withTracing(context, new SymbolicMethodParameters("enumerate", null, args), () -> symbolicMethodEnumerateKt(context, args)); } @CPythonAdapterJavaMethod(cName = "symbolic_method_list_append") @SymbolicMethod(id = SymbolicMethodId.ListAppend) - public static SymbolForCPython symbolicMethodListAppend(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodListAppend(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("list_append", self, args), () -> symbolicMethodListAppendKt(context, self, args)); } @SymbolicMethodDescriptor(nativeTypeName = "PyList_Type", nativeMemberName = "append") @@ -1284,7 +1284,7 @@ public static SymbolForCPython symbolicMethodListAppend(ConcolicRunContext conte @CPythonAdapterJavaMethod(cName = "symbolic_method_list_insert") @SymbolicMethod(id = SymbolicMethodId.ListInsert) - public static SymbolForCPython symbolicMethodListInsert(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodListInsert(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("list_insert", self, args), () -> symbolicMethodListInsertKt(context, self, args)); } @SymbolicMethodDescriptor(nativeTypeName = "PyList_Type", nativeMemberName = "insert") @@ -1292,7 +1292,7 @@ public static SymbolForCPython symbolicMethodListInsert(ConcolicRunContext conte @CPythonAdapterJavaMethod(cName = "symbolic_method_list_pop") @SymbolicMethod(id = SymbolicMethodId.ListPop) - public static SymbolForCPython symbolicMethodListPop(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodListPop(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("list_pop", self, args), () -> symbolicMethodListPopKt(context, self, args)); } @SymbolicMethodDescriptor(nativeTypeName = "PyList_Type", nativeMemberName = "pop") @@ -1300,7 +1300,7 @@ public static SymbolForCPython symbolicMethodListPop(ConcolicRunContext context, @CPythonAdapterJavaMethod(cName = "symbolic_method_list_extend") @SymbolicMethod(id = SymbolicMethodId.ListExtend) - public static SymbolForCPython symbolicMethodListExtend(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodListExtend(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("list_extend", self, args), () -> symbolicMethodListExtendKt(context, self, args)); } @SymbolicMethodDescriptor(nativeTypeName = "PyList_Type", nativeMemberName = "extend") @@ -1308,7 +1308,7 @@ public static SymbolForCPython symbolicMethodListExtend(ConcolicRunContext conte @CPythonAdapterJavaMethod(cName = "symbolic_method_list_clear") @SymbolicMethod(id = SymbolicMethodId.ListClear) - public static SymbolForCPython symbolicMethodListClear(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodListClear(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("list_clear", self, args), () -> symbolicMethodListClearKt(context, self, args)); } @SymbolicMethodDescriptor(nativeTypeName = "PyList_Type", nativeMemberName = "clear") @@ -1346,7 +1346,7 @@ public static SymbolForCPython symbolicMethodListClear(ConcolicRunContext contex @CPythonAdapterJavaMethod(cName = "symbolic_method_set_add") @SymbolicMethod(id = SymbolicMethodId.SetAdd) - public static SymbolForCPython symbolicMethodSetAdd(ConcolicRunContext context, @Nullable SymbolForCPython self, SymbolForCPython[] args) { + public static SymbolForCPython symbolicMethodSetAdd(ConcolicRunContext context, /* nullable */ SymbolForCPython self, SymbolForCPython[] args) { return withTracing(context, new SymbolicMethodParameters("set_add", self, args), () -> symbolicMethodSetAddKt(context, self, args)); }