Program: 74429
Project: 74429
Buggy source:
/** 
 * Set the type of the given node to be the return type of the function determined for the given node.
 * @param node The specified node.
 * @exception IllegalActionException If an inference error occurs.
 */
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException {
  int argCount=node.jjtGetNumChildren() - 1;
  String functionName=node.getFunctionName();
  Type[] childTypes=new Type[argCount];
  for (int i=0; i < argCount; i++) {
    childTypes[i]=_inferChild(node,i + 1);
    if (childTypes[i] == null) {
      throw new RuntimeException("String_Node_Str" + node + "String_Node_Str");
    }
  }
  Type baseType=null;
  if ((_scope != null) && (functionName != null)) {
    baseType=_scope.getType(functionName);
  }
  if ((baseType != null) || (functionName == null)) {
    baseType=_inferChild(node,0);
    if (baseType instanceof FunctionType) {
      _setType(node,((FunctionType)baseType).getReturnType());
      return;
    }
 else     if (argCount == 1) {
      if (baseType instanceof ArrayType) {
        _setType(node,((ArrayType)baseType).getElementType());
        return;
      }
 else {
        _assert(true,node,"String_Node_Str" + "String_Node_Str" + node.getFunctionName() + "String_Node_Str");
      }
    }
 else     if (argCount == 2) {
      if (baseType instanceof MatrixType) {
        _setType(node,((MatrixType)baseType).getElementType());
        return;
      }
 else {
        _assert(true,node,"String_Node_Str" + "String_Node_Str" + node.getFunctionName() + "String_Node_Str");
      }
    }
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + functionName);
  }
  if ((functionName.compareTo("String_Node_Str") == 0) && (argCount == 2)) {
    ASTPtRootNode castTypeNode=((ASTPtRootNode)node.jjtGetChild(0 + 1));
    ParseTreeEvaluator parseTreeEvaluator=new ParseTreeEvaluator();
    try {
      ptolemy.data.Token t=parseTreeEvaluator.evaluateParseTree(castTypeNode,_scope);
      _setType(node,t.getType());
    }
 catch (    IllegalActionException ex) {
      _setType(node,childTypes[0]);
    }
    return;
  }
  if ((functionName.compareTo("String_Node_Str") == 0) && (argCount == 3)) {
    ASTPtRootNode lengthNode=((ASTPtRootNode)node.jjtGetChild(1 + 1));
    ASTPtRootNode integerBitsNode=((ASTPtRootNode)node.jjtGetChild(2 + 1));
    ParseTreeEvaluator parseTreeEvaluator=new ParseTreeEvaluator();
    try {
      ptolemy.data.Token length=parseTreeEvaluator.evaluateParseTree(lengthNode,_scope);
      ptolemy.data.Token integerBits=parseTreeEvaluator.evaluateParseTree(integerBitsNode,_scope);
      _setType(node,new FixType(new Precision(((ScalarToken)length).intValue(),((ScalarToken)integerBits).intValue())));
      return;
    }
 catch (    Throwable throwable) {
    }
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    _setType(node,BaseType.GENERAL);
    return;
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    _setType(node,BaseType.GENERAL);
    return;
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    if (argCount == 3) {
      if (childTypes[0] instanceof FunctionType) {
        FunctionType function=(FunctionType)childTypes[0];
        if (function.getArgCount() != 2) {
          throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
        if (!function.getArgType(0).isCompatible(childTypes[1])) {
          throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
        }
        _setType(node,function.getReturnType());
        return;
      }
    }
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  }
  if (functionName.equals("String_Node_Str") && argCount == 1) {
    ASTPtRootNode classNameNode=((ASTPtRootNode)node.jjtGetChild(1));
    if (classNameNode instanceof ASTPtLeafNode) {
      ptolemy.data.Token token=((ASTPtLeafNode)classNameNode).getToken();
      if (token != null && token instanceof StringToken) {
        String className=((StringToken)token).stringValue();
        try {
          Class clazz=Class.forName(className);
          _setType(node,new ObjectType(clazz));
          return;
        }
 catch (        ClassNotFoundException e) {
          throw new IllegalActionException("String_Node_Str" + className);
        }
      }
    }
  }
  CachedMethod cachedMethod;
  try {
    cachedMethod=CachedMethod.findMethod(functionName,childTypes,CachedMethod.FUNCTION);
  }
 catch (  Exception ex) {
    _setType(node,BaseType.UNKNOWN);
    return;
  }
  if (cachedMethod.isValid()) {
    Type type=cachedMethod.getReturnType();
    _setType(node,type);
  }
 else {
    StringBuffer buffer=new StringBuffer();
    for (int i=0; i < childTypes.length; i++) {
      if (i == 0) {
        buffer.append(childTypes[i].toString());
      }
 else {
        buffer.append("String_Node_Str" + childTypes[i].toString());
      }
    }
    throw new IllegalActionException("String_Node_Str" + node.getFunctionName() + "String_Node_Str"+ buffer+ "String_Node_Str");
  }
}

Fixed version (ground truth):
/** 
 * Set the type of the given node to be the return type of the function determined for the given node.
 * @param node The specified node.
 * @exception IllegalActionException If an inference error occurs.
 */
public void visitFunctionApplicationNode(ASTPtFunctionApplicationNode node) throws IllegalActionException {
  int argCount=node.jjtGetNumChildren() - 1;
  String functionName=node.getFunctionName();
  Type[] childTypes=new Type[argCount];
  for (int i=0; i < argCount; i++) {
    childTypes[i]=_inferChild(node,i + 1);
    if (childTypes[i] == null) {
      throw new RuntimeException("String_Node_Str" + node + "String_Node_Str");
    }
  }
  Type type=null;
  Type baseType=null;
  if ((_scope != null) && (functionName != null)) {
    type=_scope.getType(functionName);
    if (!(type instanceof ObjectType)) {
      baseType=type;
    }
  }
  if ((baseType != null) || (functionName == null)) {
    baseType=_inferChild(node,0);
    if (baseType instanceof FunctionType) {
      _setType(node,((FunctionType)baseType).getReturnType());
      return;
    }
 else     if (argCount == 1) {
      if (baseType instanceof ArrayType) {
        _setType(node,((ArrayType)baseType).getElementType());
        return;
      }
 else {
        _assert(true,node,"String_Node_Str" + "String_Node_Str" + node.getFunctionName() + "String_Node_Str");
      }
    }
 else     if (argCount == 2) {
      if (baseType instanceof MatrixType) {
        _setType(node,((MatrixType)baseType).getElementType());
        return;
      }
 else {
        _assert(true,node,"String_Node_Str" + "String_Node_Str" + node.getFunctionName() + "String_Node_Str");
      }
    }
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + functionName);
  }
  if ((functionName.compareTo("String_Node_Str") == 0) && (argCount == 2)) {
    ASTPtRootNode castTypeNode=((ASTPtRootNode)node.jjtGetChild(0 + 1));
    ParseTreeEvaluator parseTreeEvaluator=new ParseTreeEvaluator();
    try {
      ptolemy.data.Token t=parseTreeEvaluator.evaluateParseTree(castTypeNode,_scope);
      _setType(node,t.getType());
    }
 catch (    IllegalActionException ex) {
      _setType(node,childTypes[0]);
    }
    return;
  }
  if ((functionName.compareTo("String_Node_Str") == 0) && (argCount == 3)) {
    ASTPtRootNode lengthNode=((ASTPtRootNode)node.jjtGetChild(1 + 1));
    ASTPtRootNode integerBitsNode=((ASTPtRootNode)node.jjtGetChild(2 + 1));
    ParseTreeEvaluator parseTreeEvaluator=new ParseTreeEvaluator();
    try {
      ptolemy.data.Token length=parseTreeEvaluator.evaluateParseTree(lengthNode,_scope);
      ptolemy.data.Token integerBits=parseTreeEvaluator.evaluateParseTree(integerBitsNode,_scope);
      _setType(node,new FixType(new Precision(((ScalarToken)length).intValue(),((ScalarToken)integerBits).intValue())));
      return;
    }
 catch (    Throwable throwable) {
    }
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    _setType(node,BaseType.GENERAL);
    return;
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    _setType(node,BaseType.GENERAL);
    return;
  }
  if (functionName.compareTo("String_Node_Str") == 0) {
    if (argCount == 3) {
      if (childTypes[0] instanceof FunctionType) {
        FunctionType function=(FunctionType)childTypes[0];
        if (function.getArgCount() != 2) {
          throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str");
        }
        if (!function.getArgType(0).isCompatible(childTypes[1])) {
          throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str");
        }
        _setType(node,function.getReturnType());
        return;
      }
    }
    throw new IllegalActionException("String_Node_Str" + "String_Node_Str" + "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str"+ "String_Node_Str");
  }
  if (functionName.equals("String_Node_Str") && argCount == 1) {
    ASTPtRootNode classNameNode=((ASTPtRootNode)node.jjtGetChild(1));
    if (classNameNode instanceof ASTPtLeafNode) {
      ptolemy.data.Token token=((ASTPtLeafNode)classNameNode).getToken();
      if (token != null && token instanceof StringToken) {
        String className=((StringToken)token).stringValue();
        try {
          Class clazz=Class.forName(className);
          _setType(node,new ObjectType(clazz));
          return;
        }
 catch (        ClassNotFoundException e) {
          throw new IllegalActionException("String_Node_Str" + className);
        }
      }
    }
  }
  CachedMethod cachedMethod;
  try {
    cachedMethod=CachedMethod.findMethod(functionName,childTypes,CachedMethod.FUNCTION);
  }
 catch (  Exception ex) {
    _setType(node,BaseType.UNKNOWN);
    return;
  }
  if (cachedMethod.isValid()) {
    baseType=cachedMethod.getReturnType();
    _setType(node,baseType);
    return;
  }
  if (type instanceof ObjectType) {
    _setType(node,type);
    return;
  }
  StringBuffer buffer=new StringBuffer();
  for (int i=0; i < childTypes.length; i++) {
    if (i == 0) {
      buffer.append(childTypes[i].toString());
    }
 else {
      buffer.append("String_Node_Str" + childTypes[i].toString());
    }
  }
  throw new IllegalActionException("String_Node_Str" + node.getFunctionName() + "String_Node_Str"+ buffer+ "String_Node_Str");
}