Example #1
0
  public Set<? extends IAllocNode> getPTSetOfArrayElement(IAllocNode allocNode) {
    final Set<AllocNode> ptSet = new LinkedHashSet<AllocNode>();
    if (!(allocNode.getType() instanceof ArrayType)) {
      logger.error(
          "Calling getPTSetOfArrayElement on non array type: {} with {}",
          allocNode,
          allocNode.getType());
    }

    final Type filteringType = ((ArrayType) allocNode.getType()).getElementType();

    HashPointsToSet pointsToSet = new HashPointsToSet(allocNode.getType(), ptsProvider);
    pointsToSet.add((AllocNode) allocNode);

    ((PointsToSetInternal) ptsProvider.reachingObjectsOfArrayElement(pointsToSet))
        .forall(
            new P2SetVisitor() {
              @Override
              public void visit(Node node) {
                if (typeManager.castNeverFails(node.getType(), filteringType))
                  ptSet.add((AllocNode) node);
              }
            });

    return (Set<? extends IAllocNode>) ptSet;
  }
Example #2
0
  @Override
  public Set<? extends IAllocNode> getPTSet(Value val, Context context) {
    // handle case for insensitive run
    if (k == 0) return getPTSetIns(val);

    final Set<AllocNode> allocNodes = new LinkedHashSet<AllocNode>();
    final Type filteringType = val.getType();

    PointsToSetInternal pts = null;

    try {
      if (val instanceof InstanceFieldRef) {
        final InstanceFieldRef ifr = (InstanceFieldRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjects(context, (Local) ifr.getBase(), ifr.getField());
      } else if (val instanceof ArrayRef) {
        ArrayRef arrayRef = (ArrayRef) val;
        pts =
            (PointsToSetInternal)
                ptsProvider.reachingObjectsOfArrayElement(
                    ptsProvider.reachingObjects(context, (Local) arrayRef.getBase()));
      } else if (val instanceof Local) {
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(context, (Local) val);
      } else if (val instanceof StaticFieldRef) {
        SootField field = ((StaticFieldRef) val).getField();
        pts = (PointsToSetInternal) ptsProvider.reachingObjects(field);
      } else if (val instanceof NullConstant) {
        return allocNodes;
      } else {
        logger.error("Unknown reference type for insenstive search: {} {}", val, val.getClass());
        droidsafe.main.Main.exit(1);
      }

      // visit internal points to set and grab all allocnodes
      pts.forall(
          new P2SetVisitor() {
            public void visit(Node n) {
              if (typeManager.castNeverFails(n.getType(), filteringType))
                allocNodes.add((AllocNode) n);
            }
          });

    } catch (Exception e) {
      logger.info("Some sort of error getting context insensitive points to set for {}", val, e);
      // e.printStackTrace();
    }

    return allocNodes;
  }