コード例 #1
0
 /**
  * Returns type converted to index type if needed. A index type variable in java splitter file has
  * type "int" or "int[]" instead of "long" or "long[]". This is needed if the variable or the an
  * element of the variable is used as an index to an array. This method converts the type of the
  * variable to "int_index" or "index[]" if it is used as an index to an array or an element of it
  * is used as an index to an array.
  *
  * @param type the original type of the variable.
  * @param name the name of the variable.
  * @param varInfo the VarInfo of the variable.
  * @param condition the condition in which the variable occurs.
  * @return the type converted to index type if needed.
  */
 private static String makeIndexIfNeeded(
     String type, String name, VarInfo varInfo, String condition) throws ParseException {
   if ((type.equals("int") || varInfo.type.isArray())
       && varInfo.file_rep_type != ProglangType.HASHCODE) {
     int LPAREN = 74;
     int RPAREN = 75;
     int LBRACKET = 78;
     int RBRACKET = 79;
     Stack<Boolean> inArrayIndex = new Stack<Boolean>();
     inArrayIndex.push(Boolean.FALSE);
     NodeToken[] tokens = TokenExtractor.extractTokens(condition);
     for (int i = 0; i < tokens.length; i++) {
       if (tokens[i].kind == LBRACKET) {
         inArrayIndex.push(Boolean.TRUE);
       } else if (tokens[i].kind == RBRACKET) {
         inArrayIndex.pop();
       } else if (tokens[i].kind == LPAREN) {
         inArrayIndex.push(Boolean.FALSE);
       } else if (tokens[i].kind == RPAREN) {
         inArrayIndex.pop();
       } else if (inArrayIndex.peek().booleanValue() && tokens[i].tokenImage.equals(name)) {
         if (type.equals("int") || type.equals("int_index")) {
           // Note the type can only equal "int_index" if the variable
           // was already visited by this if statement since it appears
           // more than once in the condition.
           type = "int_index";
         } else {
           type = "index[]";
         }
       }
     }
     return type;
   }
   return type;
 }
コード例 #2
0
 /**
  * requires: condition is a string representation of a conditional
  *
  * @return a list of all possible variable variable names in condition. arrays appear with "[]" at
  *     the end if their elements or accessed in the condition.
  */
 private static List<String> findPossibleClassVariables(String condition) throws ParseException {
   NodeToken[] tokens = TokenExtractor.extractTokens(condition);
   // System.out.println("TokenExtractor.extractTokens(" + condition + ") ==> " +
   // ArraysMDE.toString(tokens));
   List<String> variables = new ArrayList<String>();
   if (tokens.length >= 1) {
     if (tokens[0].kind == IDENTIFIER && (tokens.length <= 1 || tokens[1].kind != LPAREN)) {
       variables.add(tokens[0].tokenImage);
     }
   }
   if (tokens.length >= 2) {
     if (tokens[1].kind == IDENTIFIER
         && (tokens.length <= 2 || tokens[2].kind != LPAREN)
         && (!variables.contains(tokens[1].tokenImage))) {
       variables.add(tokens[1].tokenImage);
     }
   }
   for (int i = 2; i < tokens.length - 1; i++) {
     NodeToken token = tokens[i];
     if (token.kind == IDENTIFIER
         && tokens[i - 1].kind != DOT
         && tokens[i + 1].kind != LPAREN
         && (!variables.contains(token.tokenImage))) {
       variables.add(token.tokenImage);
     }
   }
   if (tokens.length >= 3) {
     int lastIndex = tokens.length - 1;
     if (tokens[lastIndex].kind == IDENTIFIER
         && tokens[lastIndex - 1].kind != DOT
         && (!variables.contains(tokens[lastIndex].tokenImage))) {
       variables.add(tokens[lastIndex].tokenImage);
     }
   }
   // System.out.println("findPossibleClassVariables(" + condition + ") ==> " +
   // variables.toString());
   return variables;
 }