Search in sources :

Example 41 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class Walker method outAMultiNewExpr.

public void outAMultiNewExpr(AMultiNewExpr node) {
    LinkedList arrayDesc = node.getArrayDescriptor();
    int descCnt = arrayDesc.size();
    List sizes = new LinkedList();
    Iterator it = arrayDesc.iterator();
    while (it.hasNext()) {
        AArrayDescriptor o = (AArrayDescriptor) it.next();
        if (o.getImmediate() != null)
            sizes.add(0, mProductions.removeLast());
        else
            break;
    }
    Type type = (Type) mProductions.removeLast();
    ArrayType arrayType = ArrayType.v(type, descCnt);
    mProductions.addLast(Jimple.v().newNewMultiArrayExpr(arrayType, sizes));
}
Also used : ArrayType(soot.ArrayType) RefType(soot.RefType) ShortType(soot.ShortType) BooleanType(soot.BooleanType) ByteType(soot.ByteType) Type(soot.Type) UnknownType(soot.UnknownType) DoubleType(soot.DoubleType) FloatType(soot.FloatType) IntType(soot.IntType) CharType(soot.CharType) LongType(soot.LongType) NullType(soot.NullType) ArrayType(soot.ArrayType) VoidType(soot.VoidType) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 42 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class MethodNodeFactory method caseNewMultiArrayExpr.

@Override
public final void caseNewMultiArrayExpr(NewMultiArrayExpr nmae) {
    ArrayType type = (ArrayType) nmae.getType();
    AllocNode prevAn = pag.makeAllocNode(new Pair<Expr, Integer>(nmae, new Integer(type.numDimensions)), type, method);
    VarNode prevVn = pag.makeLocalVarNode(prevAn, prevAn.getType(), method);
    mpag.addInternalEdge(prevAn, prevVn);
    setResult(prevAn);
    while (true) {
        Type t = type.getElementType();
        if (!(t instanceof ArrayType))
            break;
        type = (ArrayType) t;
        AllocNode an = pag.makeAllocNode(new Pair<Expr, Integer>(nmae, new Integer(type.numDimensions)), type, method);
        VarNode vn = pag.makeLocalVarNode(an, an.getType(), method);
        mpag.addInternalEdge(an, vn);
        mpag.addInternalEdge(vn, pag.makeFieldRefNode(prevVn, ArrayElement.v()));
        prevAn = an;
        prevVn = vn;
    }
}
Also used : ArrayType(soot.ArrayType) VarNode(soot.jimple.spark.pag.VarNode) RefType(soot.RefType) Type(soot.Type) RefLikeType(soot.RefLikeType) ArrayType(soot.ArrayType) NewArrayExpr(soot.jimple.NewArrayExpr) VirtualInvokeExpr(soot.jimple.VirtualInvokeExpr) PhiExpr(soot.shimple.PhiExpr) NewMultiArrayExpr(soot.jimple.NewMultiArrayExpr) CastExpr(soot.jimple.CastExpr) InvokeExpr(soot.jimple.InvokeExpr) NewExpr(soot.jimple.NewExpr) Expr(soot.jimple.Expr) StaticInvokeExpr(soot.jimple.StaticInvokeExpr) AllocNode(soot.jimple.spark.pag.AllocNode)

Example 43 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class DemandCSPointsTo method getCallTargetsForType.

protected Set<SootMethod> getCallTargetsForType(Type type, NumberedString methodStr, Type receiverType, Set<SootMethod> possibleTargets) {
    if (!pag.getTypeManager().castNeverFails(type, receiverType))
        return Collections.<SootMethod>emptySet();
    if (type instanceof AnySubType) {
        AnySubType any = (AnySubType) type;
        RefType refType = any.getBase();
        if (pag.getTypeManager().getFastHierarchy().canStoreType(receiverType, refType) || pag.getTypeManager().getFastHierarchy().canStoreType(refType, receiverType)) {
            return possibleTargets;
        } else {
            return Collections.<SootMethod>emptySet();
        }
    }
    if (type instanceof ArrayType) {
        // we'll invoke the java.lang.Object method in this
        // case
        // Assert.chk(varNodeType.toString().equals("java.lang.Object"));
        type = Scene.v().getSootClass("java.lang.Object").getType();
    }
    RefType refType = (RefType) type;
    SootMethod targetMethod = null;
    targetMethod = VirtualCalls.v().resolveNonSpecial(refType, methodStr);
    return Collections.<SootMethod>singleton(targetMethod);
}
Also used : RefType(soot.RefType) ArrayType(soot.ArrayType) SootMethod(soot.SootMethod) AnySubType(soot.AnySubType)

Example 44 with ArrayType

use of soot.ArrayType in project soot by Sable.

the class SparkLibraryHelper method caseArrayType.

/**
 * A new local array will be created and connected to
 * {@link SparkLibraryHelper#node} of type {@link ArrayType}. For this new
 * local an allocation edge to a new array of its declared type will be
 * added. If the {@link ArrayType#getElementType()} is still an array an
 * allocation to a new array of this element type will be made and stored
 * until the element type is a {@link RefType}. If this is the case an
 * allocation to {@link AnySubType} of {@link ArrayType#baseType} will be
 * made.
 */
@Override
public void caseArrayType(ArrayType type) {
    Node array = node;
    for (Type t = type; t instanceof ArrayType; t = ((ArrayType) t).getElementType()) {
        ArrayType at = (ArrayType) t;
        if (at.baseType instanceof RefType) {
            // var tmpArray;
            LocalVarNode localArray = pag.makeLocalVarNode(new Object(), t, method);
            // x = tmpArray;
            pag.addEdge(localArray, array);
            // new T[]
            AllocNode newArray = pag.makeAllocNode(new Object(), at, method);
            // tmpArray = new T[]
            pag.addEdge(newArray, localArray);
            // tmpArray[i]
            FieldRefNode arrayRef = pag.makeFieldRefNode(localArray, ArrayElement.v());
            // var tmp
            LocalVarNode local = pag.makeLocalVarNode(new Object(), at.getElementType(), method);
            // tmpArray[i] = tmp
            pag.addEdge(local, arrayRef);
            // x = tmp
            array = local;
            if (at.numDimensions == 1) {
                // new T()
                AllocNode alloc = pag.makeAllocNode(new Object(), AnySubType.v((RefType) at.baseType), method);
                // tmp = new T()
                pag.addEdge(alloc, local);
            }
        }
    }
}
Also used : ArrayType(soot.ArrayType) RefType(soot.RefType) RefType(soot.RefType) ArrayType(soot.ArrayType) AnySubType(soot.AnySubType) Type(soot.Type) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) AllocNode(soot.jimple.spark.pag.AllocNode) FieldRefNode(soot.jimple.spark.pag.FieldRefNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode) Node(soot.jimple.spark.pag.Node) VarNode(soot.jimple.spark.pag.VarNode) AllocNode(soot.jimple.spark.pag.AllocNode) LocalVarNode(soot.jimple.spark.pag.LocalVarNode)

Aggregations

ArrayType (soot.ArrayType)44 Type (soot.Type)34 RefType (soot.RefType)26 Local (soot.Local)19 Value (soot.Value)18 IntType (soot.IntType)17 BooleanType (soot.BooleanType)14 NewArrayExpr (soot.jimple.NewArrayExpr)13 ByteType (soot.ByteType)12 FloatType (soot.FloatType)12 NullType (soot.NullType)12 ShortType (soot.ShortType)12 ArrayRef (soot.jimple.ArrayRef)12 CharType (soot.CharType)11 DoubleType (soot.DoubleType)11 LongType (soot.LongType)11 AssignStmt (soot.jimple.AssignStmt)11 SootClass (soot.SootClass)10 InvokeExpr (soot.jimple.InvokeExpr)10 PrimType (soot.PrimType)9