Package dk.brics.string.intermediate

Examples of dk.brics.string.intermediate.Statement


            int counter = 0;
            for (Statement pred : r.getPreds()) {
              predsMap.put(counter, pred);
              counter++;
            }
            Statement first = copiedAssigns.getFirst();
            for (int i=0; i<predsMap.size(); i++) {
              Statement pred = predsMap.get(i);
              pred.getSuccs().remove(r);
              pred.addSucc(first);
              r.getPreds().remove(pred);
            }
            copiedAssigns.getLast().addSucc(r);
          }
        }
View Full Code Here


     * method in the worklist for all statements affected by the change.
     */
    public void iterate() {
        // TODO: better worklist strategy
        while (!list.isEmpty()) {
            Statement s = list.removeFirst();
            fa.transfer(s);
        }
    }
View Full Code Here

                   
                    LinkedList<Statement> queue = new LinkedList<Statement>();
                    Set<Statement> seen = new HashSet<Statement>();
                    queue.addAll(s.getSuccs());
                    while (!queue.isEmpty()) { // look along successors ss...
                        Statement ss = queue.removeFirst();
                        if (!seen.contains(ss)) {
                            seen.add(ss);
                            putDef(ss, v, s); // if ss uses v then s might have defined it
                            if (!dvs.defines(ss, v) && la.getLiveAfter(ss).contains(v)) // continue along successors if v is live and not defined by ss
                            {
                                queue.addAll(ss.getSuccs());
                            }
                        }
                    }
                }
            }
View Full Code Here

        }

        // get the intermediate statements corresponding to each hotspot
        Set<Statement> hotspot_statements = new HashSet<Statement>();
        for (ValueBox b : hotspots) {
            Statement stm = m1.get(b);
            if (stm == null) {
                log.info("Invalid hotspot");
                continue;
            }
            hotspot_statements.add(stm);
View Full Code Here

       
        // connect according to normal flow
        AssertionContext assertionContext = new AssertionContext(jt, definitions, translations, sootMethod);
        BriefUnitGraph normalFlow = new BriefUnitGraph(body);
        for (Unit stmt : body.getUnits()) {
            Statement tail = translations.get(stmt).getLast();
           
            if (stmt instanceof IfStmt) {
                // branching statement: link assertion in-between its successors
                IfStmt ifstmt = (IfStmt)stmt;
               
                Stmt trueSuccessor = ifstmt.getTarget();
                Stmt falseSuccessor = (Stmt)body.getUnits().getSuccOf(ifstmt);
                AssertionBranches assertions = assertionCreator.createAssertions(ifstmt, assertionContext);
               
                tail.addSucc(assertions.getWhenFalse().getFirst());
                tail.addSucc(assertions.getWhenTrue().getFirst());
               
                assertions.getWhenFalse().getLast().addSucc(translations.get(falseSuccessor).getFirst());
                assertions.getWhenTrue().getLast().addSucc(translations.get(trueSuccessor).getFirst());
            }
            else if (stmt instanceof LookupSwitchStmt) {
              LookupSwitchStmt sw = (LookupSwitchStmt)stmt;
             
              // add cases
              List<Integer> values = new ArrayList<Integer>();
              for (int i=0; i<sw.getTargetCount(); i++) {
                Stmt succ = (Stmt)sw.getTarget(i);
                AssertionBranch assertion = assertionCreator.createSwitchAssertions(sw.getKeyBox(), sw.getLookupValue(i), sw, assertionContext);
               
                tail.addSucc(assertion.getFirst());
                assertion.getLast().addSucc(translations.get(succ).getFirst());
               
                values.add(sw.getLookupValue(i));
              }
             
              // add default case
              AssertionBranch assertion = assertionCreator.createSwitchDefaultAssertions(sw.getKeyBox(), values, sw, assertionContext);
              tail.addSucc(assertion.getFirst());
              assertion.getLast().addSucc(translations.get(sw.getDefaultTarget()).getFirst());
            }
            else {
                // normal statement
              for (Unit succ : normalFlow.getSuccsOf(stmt)) {
                  tail.addSucc(translations.get(succ).getFirst());
              }
            }
        }
       
        // connect first statements to the head
View Full Code Here

    reaching.add(translation.getLast());
    queue.add(translation.getLast());
   
    // color all nodes reachable using predecessor edges from the last statement
    while (!queue.isEmpty()) {
      Statement stm = queue.removeFirst();
      for (Statement pred : stm.getPreds()) {
        if (reaching.contains(pred))
          continue;
        reaching.add(pred);
        queue.add(pred);
      }
    }
    // see if we can find a non-colored node
    Set<Statement> seen = new HashSet<Statement>();
    queue.add(translation.getFirst());
    while (!queue.isEmpty()) {
      Statement stm = queue.removeFirst();
      if (!reaching.contains(stm))
        throw new RuntimeException("Invalid statement translation. This statement cannot not reach the end: " + stm);
      seen.add(stm);
      for (Statement succ : stm.getSuccs()) {
        if (seen.contains(succ))
          continue;
        queue.add(succ);
      }
    }
View Full Code Here

    public void startBranch() {
        // if no statement has been created, add a Nop as the start of the branch
        if (firstStatement == null) {
            addStatement(new Nop());
        }
        Statement start = lastStatement;
        Statement end = new Nop();
        branchWasUsed = false;
        branches.add(new Branching(start, end));
        method.addStatement(end);
    }
View Full Code Here

        ControlFlowBuilder cfg = new ControlFlowBuilder(wrapper);
        cfg.moveToStatement(wrapper.getEntry());
       
        // create a variable holding any string
        Variable anyVar = application.createVariable(VariableType.STRING);
        Statement assignAny = new StringInit(anyVar, Basic.makeAnyString());
        cfg.addStatement(assignAny);

        // create a variable holding the null string
        Variable nullVar = application.createVariable(VariableType.STRING);
        Statement assignNull = new StringInit(nullVar, Automatons.getNull());
        cfg.addStatement(assignNull);
       
        // initialize externally visible field variables to anything
        // and set string fields to "null"
        for (SootClass ac : getApplicationClasses()) {
            for (SootField field : ac.getFields()) {
                // String fields should be assigned to "null" because they are
                // exempt from the
                // null-pointer analysis we use for other objects
                if (field.getType().equals(RefType.v("java.lang.String"))) {
                    FieldAssignment assignment = new FieldAssignment(
                            variableManager.getField(field), nullVar);
                    cfg.addStatement(assignment);
                }

                // corrupt externally visible fields
                if (ext.isExternallyVisibleField(field)) {
                    VariableType type = fromSootType(field
                            .getType());

                    if (type == VariableType.NONE)
                        continue;

                    Variable fieldInit;

                    switch (type) {
                    case OBJECT:
                    case STRING:
                    case PRIMITIVE:
                        fieldInit = anyVar;
                        break;

                    case STRINGBUFFER: {
                        fieldInit = application.createVariable(VariableType.STRINGBUFFER);
                        Statement s = new StringBufferCorrupt(fieldInit);
                        cfg.addStatement(s);
                        break;
                    }

                    case ARRAY: {
                        fieldInit = application.createVariable(VariableType.ARRAY);
                        Statement s = new ArrayCorrupt(fieldInit);
                        cfg.addStatement(s);
                        break;
                    }
                    default:
                        throw new RuntimeException("Unknown field type " + type);
                    }// switch

                    FieldAssignment assignment = new FieldAssignment(variableManager.getField(field), fieldInit);
                    cfg.addStatement(assignment);
                }
            }
        }
       
        // split control here, and call a random externally visible method
        cfg.startBranch();
       
        // call externally visible methods
        for (SootClass ac : getApplicationClasses()) {
            for (SootMethod sm : ac.getMethods()) {
                if (ext.isExternallyVisibleMethod(sm)) {
                    Method m = sms_m.get(sm.getSignature());
                    Variable[] params = m.getEntry().params;
                    Variable[] args = new Variable[params.length];
                    for (int i = 0; i < params.length; i++) {
                        Variable arg = application.createVariable(params[i].getType());
                        args[i] = arg;
                        Statement s;
                        switch (arg.getType()) {
                        case STRING:
                            s = new StringInit(arg, Basic.makeAnyString());
                            break;
                        case STRINGBUFFER:
View Full Code Here

          // assertions referring to a nop statement must have their target updated to the nop's predecessor,
          // or in case there are multiple predecessors, the nop must not be removed
          for (Statement s : m.getStatements()) {
            if (s instanceof AssertStatement) {
              AssertStatement a = (AssertStatement)s;
              Statement target = a.targetStatement;
              while (target instanceof Nop && target.getPreds().size() == 1) {
                target = target.getPreds().iterator().next();
                a.targetStatement = target;
              }
              if (target instanceof Nop) {
                protectedNops.add(target);
              }
View Full Code Here

TOP

Related Classes of dk.brics.string.intermediate.Statement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.