コード例 #1
0
  private String getExpr(ExprContext expr) {
    String output = "";
    /////
    // float, int, char, char*

    if (expr.getChildCount() == 1) {
      if (expr.FLOAT() != null || expr.INT() != null) {
        return expr.getText().toString();
      } else if (expr.ID() != null) {
        return this.variableTrack.get(expr.getText());
      } else if (expr.defExpr() != null) {
        DefExprContext def = expr.defExpr();
        output = "(valueOf " + this.variableTrack.get(def.ID().getText()) + ")";
      } else if (expr.addressExpr() != null) {
        AddressExprContext add = expr.addressExpr();
        output = "(addressOf " + this.variableTrack.get(add.ID().getText()) + ")";
      } else if (expr.CharacterLiteral() != null) {
        String ch = expr.CharacterLiteral().getText();
        int value = ch.charAt(1);
        return Integer.toString(value);
      } else if (expr.convertExpr() != null) {
        return expr.convertExpr().ID().getText();
      }

    } else {
      String operator = expr.getChild(1).getText();
      if (operator.equals("%")) operator = "mod";
      return "(" + operator + " " + getExpr(expr.expr(0)) + " " + getExpr(expr.expr(1)) + ")";
    }
    return output;
  }
コード例 #2
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);
     }
   }
 }