Exemplo n.º 1
0
 private void convert(AssignStatContext assign) {
   if (assign.getChildCount() == 5) {
     covertPointerAssgin(assign);
   } else if (assign.getChildCount() == 4) {
     convertNonPointerAssign(assign);
   }
 }
Exemplo n.º 2
0
 private void covertPointerAssgin(AssignStatContext assign) {
   String ID = assign.ID().getText();
   ExprContext temp = assign.expr();
   String id = this.variableTrack.get(ID);
   String newId = generateNewName(id);
   String constraint = "(assert (= valueOf " + newId + " " + getExpr(temp) + "))";
   ssa.add(constraint);
 }
Exemplo n.º 3
0
 private void convertNonCallExprAssign(AssignStatContext assign) {
   if (assign.StringLiteral() != null
       || this.variableType.get(assign.ID().getText()).equals("char*")) {
     convertString(assign);
   } else if (assign.condExpr() != null) {
     convertCondAssign(assign);
   } else {
     converNonString(assign);
   }
 }
Exemplo n.º 4
0
 private void convertNonPointerAssign(AssignStatContext assign) {
   // call assign or no call assign
   if (assign.callExpr() != null) {
     String id = assign.ID().getText();
     String returnId = this.generateNewName(id);
     convert(returnId, assign.callExpr());
   } else {
     convertNonCallExprAssign(assign);
   }
 }
Exemplo n.º 5
0
 private void converNonString(AssignStatContext c) {
   String expr = getExpr(c.expr());
   String id = this.variableTrack.get(c.ID().getText());
   String newId = generateNewName(id);
   String constraint = "";
   if (c.assiginOperator().getText().equals("=")) {
     constraint = "(assert(= " + newId + " " + expr + "))";
   } else {
     char operater = c.assiginOperator().getText().charAt(0);
     constraint = "(assert(= " + newId + "( " + operater + " " + id + " " + expr + " )))";
   }
   ssa.add(constraint);
 }
Exemplo n.º 6
0
 private void convertCondAssign(AssignStatContext assign) {
   String condExpr = getCondExprInAssign(assign.condExpr());
   String id = this.variableTrack.get(assign.ID().getText());
   String newId = generateNewName(id);
   String constraint = "";
   if (assign.assiginOperator().getText().equals("=")) {
     constraint = "(assert(= " + newId + " " + condExpr + "))";
   } else {
     char operater = assign.assiginOperator().getText().charAt(0);
     constraint = "(assert(= " + newId + "( " + operater + " " + id + " " + condExpr + " )))";
   }
   ssa.add(constraint);
 }
Exemplo n.º 7
0
 private void convertString(AssignStatContext c) {
   if (c.StringLiteral() != null) {
     String content = c.StringLiteral().getText().replace("\\n", "\n");
     content = content.substring(1, content.length() - 1);
     String id = c.ID().getText();
     String newId = this.generateNewName(id);
     StringRepresentation rep = new StringRepresentation(newId, content);
     // System.out.println(rep.getConstraints());
     ssa.addAll(rep.getConstraints());
   } else {
     ExprContext expr = c.expr();
     if (expr.getChildCount() == 1) {
       String id = c.ID().getText();
       String newId = this.generateNewName(id);
       String constraint = "(assert (= " + newId + " " + this.getExpr(expr) + "))";
       this.ssa.add(constraint);
     } else {
       String id = c.ID().getText();
       String newId = this.generateNewName(id);
       String constraint =
           "(assert (= "
               + "(valueOf "
               + newId
               + ") (charOf "
               + this.getExpr(expr.expr(0))
               + " "
               + this.getExpr(expr.expr(1))
               + ")))";
       this.ssa.add(constraint);
     }
   }
 }