Skip to content

Commit

Permalink
Add sq_concat notification
Browse files Browse the repository at this point in the history
  • Loading branch information
jefremof committed Aug 13, 2024
1 parent b56e3a2 commit d4ab7a6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,18 @@ public static void notifyNbPositive(ConcolicRunContext context, SymbolForCPython
nbPositiveKt(context, on.obj);
}

@CPythonAdapterJavaMethod(cName = "sq_concat")
@CPythonFunction(
argCTypes = {CType.PyObject, CType.PyObject},
argConverters = {ObjectConverter.StandardConverter, ObjectConverter.StandardConverter}
)
public static void notifySqConcat(ConcolicRunContext context, SymbolForCPython left, SymbolForCPython right) {
if (left.obj == null || right.obj == null)
return;
context.curOperation = new MockHeader(SqConcatMethod.INSTANCE, Arrays.asList(left.obj, right.obj), null);
sqConcatKt(context, left.obj, right.obj);
}

@CPythonAdapterJavaMethod(cName = "sq_length")
@CPythonFunction(
argCTypes = {CType.PyObject},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ data object NbMultiplyMethod : TypeMethod(false)
data object NbMatrixMultiplyMethod : TypeMethod(false)
data object NbNegativeMethod : TypeMethod(false)
data object NbPositiveMethod : TypeMethod(false)
data object SqConcatMethod : TypeMethod(false)
data object SqLengthMethod : TypeMethod(true)
data object MpSubscriptMethod : TypeMethod(false)
data object MpAssSubscriptMethod : TypeMethod(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ fun nbPositiveKt(context: ConcolicRunContext, on: UninterpretedSymbolicPythonObj
pyAssert(context, on.evalIsSoft(context, HasNbPositive))
}

fun sqConcatKt(
context: ConcolicRunContext,
left: UninterpretedSymbolicPythonObject,
right: UninterpretedSymbolicPythonObject,
) = with(
context.ctx
) {
context.curState ?: return
pyAssert(context, left.evalIsSoft(context, HasSqConcat) and right.evalIsSoft(context, HasSqConcat))
}

fun sqLengthKt(context: ConcolicRunContext, on: UninterpretedSymbolicPythonObject) {
context.curState ?: return
val sqLength = on.evalIsSoft(context, HasSqLength)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.usvm.language.NbMultiplyMethod
import org.usvm.language.NbNegativeMethod
import org.usvm.language.NbPositiveMethod
import org.usvm.language.NbSubtractMethod
import org.usvm.language.SqConcatMethod
import org.usvm.language.SqLengthMethod
import org.usvm.language.TpCallMethod
import org.usvm.language.TpGetattro
Expand Down Expand Up @@ -95,6 +96,10 @@ class SymbolTypeTree(
listOf(createBinaryProtocol("__mul__", pythonAnyType, returnType))
}

SqConcatMethod -> { returnType: UtType ->
listOf(createBinaryProtocol("__add__", pythonAnyType, returnType))
}

SqLengthMethod -> { _: UtType ->
listOf(createUnaryProtocol("__len__", typeHintsStorage.pythonInt))
}
Expand Down

0 comments on commit d4ab7a6

Please sign in to comment.