Пример #1
0
  // this is used just for strcpy, strncpy, strncat, strncat
  private void convert(CallStatContext callStat) {
    CallExprContext c = callStat.callExpr();
    String function = c.ID().getText();
    if (function.equals("strcpy")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getstrcpyConstraints(newDest, source);
      ssa.addAll(constraints);
    } else if (function.equals("strncpy")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      FormalArgumentContext argument3 = c.arguments().formalArgument(2);
      String num = argument3.ID().getText();
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getstrncpyConstraints(newDest, source, num);
      ssa.addAll(constraints);

    } else if (function.equals("strcat")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getStrcatConstraints(dest, source, newDest);
      ssa.addAll(constraints);

    } else if (function.equals("strncat")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      FormalArgumentContext argument3 = c.arguments().formalArgument(2);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String num = argument3.ID().getText();
      String newDest = generateNewName(dest);
      List<String> constraints =
          StringMethodTranslator.getStrncatConstraints(dest, source, num, newDest);
      ssa.addAll(constraints);
    } else {

    }
  }
Пример #2
0
  // convert assign call statement
  private void convert(String returnId, CallExprContext c) {

    String function = c.ID().getText();
    if (function.equals("strcpy")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);

      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getstrcpyConstraints(newDest, source);
      ssa.addAll(constraints);
      String returnCon = "(assert (= " + returnId + " " + newDest + "))";
      ssa.add(returnCon);
    } else if (function.equals("strncpy")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      FormalArgumentContext argument3 = c.arguments().formalArgument(2);
      String num = argument3.ID().getText();
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getstrncpyConstraints(newDest, source, num);
      ssa.addAll(constraints);
      String returnCon = "(assert (= " + returnId + " " + newDest + "))";
      ssa.add(returnCon);
    } else if (function.equals("strcat")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String newDest = generateNewName(dest);
      List<String> constraints = StringMethodTranslator.getStrcatConstraints(dest, source, newDest);
      ssa.addAll(constraints);
      String returnCon = "(assert (= " + returnId + " " + newDest + "))";
      ssa.add(returnCon);
    } else if (function.equals("strncat")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      FormalArgumentContext argument3 = c.arguments().formalArgument(2);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String num = argument3.ID().getText();
      String newDest = generateNewName(dest);
      List<String> constraints =
          StringMethodTranslator.getStrncatConstraints(dest, source, num, newDest);
      ssa.addAll(constraints);
      String returnCon = "(assert (= " + returnId + " " + newDest + "))";
      ssa.add(returnCon);
    } else if (function.equals("strcmp")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String compare = StringMethodTranslator.getStrcmpConstraints(dest, source);
      String returnCon = "(assert (= " + returnId + " " + compare + "))";
      ssa.add(returnCon);
    } else if (function.equals("strncmp")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      FormalArgumentContext argument2 = c.arguments().formalArgument(1);
      FormalArgumentContext argument3 = c.arguments().formalArgument(2);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String source = this.variableTrack.get(argument2.ID().getText());
      String num = argument3.ID().getText();
      String compare = StringMethodTranslator.getStrncmpConstraints(dest, source, num);
      String returnCon = "(assert (= " + returnId + " " + compare + "))";
      ssa.add(returnCon);
    } else if (function.equals("strlen")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String len = StringMethodTranslator.getStrlenConstraints(dest);
      String returnCon = "(assert (= " + returnId + " " + len + "))";
      ssa.add(returnCon);
    } else if (function.equals("isdigit")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String result = CharMethodTranslator.getIsDigitConstraint(returnId, dest);

      ssa.add(result);
    } else if (function.equals("isupper")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String result = CharMethodTranslator.getIsUpperConstraint(returnId, dest);
      ssa.add(result);
    } else if (function.equals("islower")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String result = CharMethodTranslator.getIsLowerConstraint(returnId, dest);
      ssa.add(result);
    } else if (function.equals("tolower")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String result = CharMethodTranslator.getToLowerConstraint(returnId, dest);
      ssa.add(result);
    } else if (function.equals("toupper")) {
      FormalArgumentContext argument1 = c.arguments().formalArgument(0);
      String dest = this.variableTrack.get(argument1.ID().getText());
      String result = CharMethodTranslator.getToUpperConstraint(returnId, dest);
      ssa.add(result);
    }
  }