Program: 75487
Project: 75487
Buggy source:
/** 
 * Visit the relation node. The evaluation part is the same as normal parseTreeEvaluator, except that information about each relation (the difference and relationType) is either added into the relation list or used to update the according element in the relation list, depending on the evaluator mode.
 * @param node The relation node to be evaluated.
 * @exception IllegalActionException If the super class methodvisitRelationNode throws the IllegalActionException.
 */
public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException {
  if (node.isConstant() && node.isEvaluated()) {
    return;
  }
  Set variablesOfNode=_variableCollector.collectFreeVariables(node);
  Iterator absentDiscreteVariables=_absentDiscreteVariables.listIterator();
  while (absentDiscreteVariables.hasNext()) {
    String variableName=(String)absentDiscreteVariables.next();
    if (variablesOfNode.contains(variableName)) {
      _evaluatedChildToken=new BooleanToken(false);
      if (_constructingRelationList) {
        _relationList.addRelation(0,0.0);
      }
      _relationIndex++;
      if (_relationIndex >= _relationList.length()) {
        _relationIndex-=_relationList.length();
      }
      return;
    }
  }
  ptolemy.data.Token[] tokens=_evaluateAllChildren(node);
  int numChildren=node.jjtGetNumChildren();
  _assert(numChildren == 2,node,"String_Node_Str");
  ptolemy.data.expr.Token operator=(ptolemy.data.expr.Token)node.getOperator();
  ptolemy.data.Token leftToken=tokens[0];
  ptolemy.data.Token rightToken=tokens[1];
  ptolemy.data.Token result;
  if (operator.kind == PtParserConstants.EQUALS || operator.kind == PtParserConstants.NOTEQUALS) {
    if (operator.kind == PtParserConstants.EQUALS) {
      result=leftToken.isCloseTo(rightToken,_errorTolerance);
    }
 else {
      result=leftToken.isCloseTo(rightToken,_errorTolerance).not();
    }
    if ((leftToken instanceof BooleanToken) && (rightToken instanceof BooleanToken)) {
      if (((BooleanToken)result).booleanValue()) {
        _relationType=1;
      }
 else {
        _relationType=2;
      }
      _difference=0.0;
    }
 else {
      ScalarToken difference=(ScalarToken)leftToken.subtract(rightToken);
      if (((BooleanToken)result).booleanValue()) {
        _relationType=3;
      }
 else {
        if (difference.doubleValue() < 0) {
          _relationType=4;
        }
 else {
          _relationType=5;
        }
      }
      _difference=difference.doubleValue();
    }
  }
 else {
    if (!((leftToken instanceof ScalarToken) && (rightToken instanceof ScalarToken))) {
      throw new IllegalActionException("String_Node_Str" + operator.image + "String_Node_Str");
    }
    ScalarToken leftScalar=(ScalarToken)leftToken;
    ScalarToken rightScalar=(ScalarToken)rightToken;
    if (operator.kind == PtParserConstants.GTE) {
      result=leftScalar.isLessThan(rightScalar).not();
    }
 else     if (operator.kind == PtParserConstants.GT) {
      result=rightScalar.isLessThan(leftScalar);
    }
 else     if (operator.kind == PtParserConstants.LTE) {
      result=rightScalar.isLessThan(leftScalar).not();
    }
 else     if (operator.kind == PtParserConstants.LT) {
      result=leftScalar.isLessThan(rightScalar);
    }
 else {
      throw new IllegalActionException("String_Node_Str" + operator.image + "String_Node_Str"+ leftToken.getClass().getName()+ "String_Node_Str"+ rightToken.getClass().getName());
    }
    if (((BooleanToken)result).booleanValue()) {
      _relationType=1;
    }
 else {
      _relationType=2;
    }
    _difference=((ScalarToken)leftScalar.subtract(rightScalar)).doubleValue();
  }
  _evaluatedChildToken=result;
  if (_constructingRelationList) {
    _relationList.addRelation(_relationType,_difference);
  }
 else {
    _relationList.setRelation(_relationIndex,_relationType,_difference);
  }
  _relationIndex++;
  if (_relationIndex >= _relationList.length()) {
    _relationIndex-=_relationList.length();
  }
  return;
}

Fixed version (ground truth):
/** 
 * Visit the relation node. The evaluation part is the same as normal parseTreeEvaluator, except that information about each relation (the difference and relationType) is either added into the relation list or used to update the according element in the relation list, depending on the evaluator mode.
 * @param node The relation node to be evaluated.
 * @exception IllegalActionException If the super class methodvisitRelationNode throws the IllegalActionException.
 */
public void visitRelationalNode(ASTPtRelationalNode node) throws IllegalActionException {
  if (node.isConstant() && node.isEvaluated()) {
    return;
  }
  Set variablesOfNode=_variableCollector.collectFreeVariables(node);
  Iterator absentDiscreteVariables=_absentDiscreteVariables.listIterator();
  while (absentDiscreteVariables.hasNext()) {
    String variableName=(String)absentDiscreteVariables.next();
    if (variablesOfNode.contains(variableName)) {
      _evaluatedChildToken=new BooleanToken(false);
      if (_constructingRelationList) {
        _relationList.addRelation(0,0.0);
      }
      _relationIndex++;
      if (_relationIndex >= _relationList.length()) {
        _relationIndex-=_relationList.length();
      }
      return;
    }
  }
  ptolemy.data.Token[] tokens=_evaluateAllChildren(node);
  int numChildren=node.jjtGetNumChildren();
  _assert(numChildren == 2,node,"String_Node_Str");
  ptolemy.data.expr.Token operator=(ptolemy.data.expr.Token)node.getOperator();
  ptolemy.data.Token leftToken=tokens[0];
  ptolemy.data.Token rightToken=tokens[1];
  ptolemy.data.Token result;
  if (operator.kind == PtParserConstants.EQUALS || operator.kind == PtParserConstants.NOTEQUALS) {
    if (operator.kind == PtParserConstants.EQUALS) {
      result=leftToken.isCloseTo(rightToken,_errorTolerance);
    }
 else {
      result=leftToken.isCloseTo(rightToken,_errorTolerance).not();
    }
    if ((leftToken instanceof ScalarToken) && (rightToken instanceof ScalarToken)) {
      ScalarToken difference=(ScalarToken)leftToken.subtract(rightToken);
      if (((BooleanToken)result).booleanValue()) {
        _relationType=3;
      }
 else {
        if (difference.doubleValue() < 0) {
          _relationType=4;
        }
 else {
          _relationType=5;
        }
      }
      _difference=difference.doubleValue();
    }
 else {
      if (((BooleanToken)result).booleanValue()) {
        _relationType=1;
      }
 else {
        _relationType=2;
      }
      _difference=0.0;
    }
  }
 else {
    if (!((leftToken instanceof ScalarToken) && (rightToken instanceof ScalarToken))) {
      throw new IllegalActionException("String_Node_Str" + operator.image + "String_Node_Str");
    }
    ScalarToken leftScalar=(ScalarToken)leftToken;
    ScalarToken rightScalar=(ScalarToken)rightToken;
    if (operator.kind == PtParserConstants.GTE) {
      result=leftScalar.isLessThan(rightScalar).not();
    }
 else     if (operator.kind == PtParserConstants.GT) {
      result=rightScalar.isLessThan(leftScalar);
    }
 else     if (operator.kind == PtParserConstants.LTE) {
      result=rightScalar.isLessThan(leftScalar).not();
    }
 else     if (operator.kind == PtParserConstants.LT) {
      result=leftScalar.isLessThan(rightScalar);
    }
 else {
      throw new IllegalActionException("String_Node_Str" + operator.image + "String_Node_Str"+ leftToken.getClass().getName()+ "String_Node_Str"+ rightToken.getClass().getName());
    }
    if (((BooleanToken)result).booleanValue()) {
      _relationType=1;
    }
 else {
      _relationType=2;
    }
    _difference=((ScalarToken)leftScalar.subtract(rightScalar)).doubleValue();
  }
  _evaluatedChildToken=result;
  if (_constructingRelationList) {
    _relationList.addRelation(_relationType,_difference);
  }
 else {
    _relationList.setRelation(_relationIndex,_relationType,_difference);
  }
  _relationIndex++;
  if (_relationIndex >= _relationList.length()) {
    _relationIndex-=_relationList.length();
  }
  return;
}