Program: 72867
Project: 72867
Buggy source:
/** 
 * Generate the code of the declaration of an IOPort (or a subclass) Initialize all its dependencies (container, widths ...) In this base class we deal with all the known kinds of ports, however ideally we should create an adapter for each type of port. There are essentially four types of ports : - input/output - from a composite/atomic actor The creation of the receivers relies on this distinction.
 * @return the port declaration to include in the actor constructor
 * @exception IllegalActionException if the getWidth or getWidthInsidethrows an exception 
 */
public String generatePortDeclaration() throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  TemplateParser tParser=getTemplateParser();
  ProgramCodeGenerator codeGenerator=getCodeGenerator();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  String portName=port.getName();
  String typePort=port.getClass().getSimpleName();
  if (port instanceof ParameterPort || port instanceof PubSubPort)   typePort="String_Node_Str";
  NamedObj actor=port.getContainer();
  String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
  if (!port.isInsideConnected() && !port.isOutsideConnected())   return "String_Node_Str";
  result.append(portName + "String_Node_Str" + typePort+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isInsideConnected()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isOutsideConnected()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isInput()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isOutput()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isMultiport()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.getWidth()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.getWidthInside()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.numberOfSinks()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.numberOfSources()+ "String_Node_Str"+ _eol);
  Parameter parameter=(Parameter)((NamedObj)port).getAttribute("String_Node_Str");
  Double ioPortDelayOffset=null;
  if (parameter != null) {
    Token token=parameter.getToken();
    if (token instanceof DoubleToken) {
      ioPortDelayOffset=((DoubleToken)token).doubleValue();
    }
 else     if (token instanceof ArrayToken) {
      ioPortDelayOffset=((DoubleToken)((ArrayToken)token).getElement(0)).doubleValue();
    }
  }
  if (ioPortDelayOffset != null)   result.append(portName + "String_Node_Str" + ioPortDelayOffset.doubleValue()+ "String_Node_Str"+ _eol);
  if (port instanceof MirrorPort) {
    MirrorPort mport=(MirrorPort)port;
    MirrorPort associatedPort=mport.getAssociatedPort();
    String accessorAssociatedPort=CodeGeneratorAdapter.generateName(associatedPort.getContainer()) + "String_Node_Str" + associatedPort.getName()+ "String_Node_Str";
    result.append("String_Node_Str" + portName + "String_Node_Str"+ accessorAssociatedPort+ "String_Node_Str"+ _eol);
    if (mport instanceof PtidesPort) {
      PtidesPort ptidesPort=(PtidesPort)mport;
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((BooleanToken)ptidesPort.actuateAtEventTimestamp.getToken()).booleanValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.deviceDelay.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.deviceDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((BooleanToken)ptidesPort.isNetworkPort.getToken()).booleanValue()+ "String_Node_Str"+ _eol);
      if (ptidesPort.isNetworkReceiverPort() || ptidesPort.isNetworkTransmitterPort()) {
        result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.networkDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
        result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.sourcePlatformDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      }
    }
  }
  if (port instanceof TypedIOPort) {
    TypedIOPort typedPort=(TypedIOPort)port;
    String type=codeGenerator.codeGenType(typedPort.getType());
    if (type.contains("String_Node_Str")) {
      result.append(portName + "String_Node_Str" + _eol);
      tParser.addNewTypesUsed("String_Node_Str");
      for (      String typ : type.split("String_Node_Str")) {
        tParser.addNewTypesUsed(typ);
      }
    }
 else {
      result.append(portName + "String_Node_Str" + type+ "String_Node_Str"+ _eol);
      tParser.addNewTypesUsed(type);
    }
  }
  int foo=0;
  if (port.isInput())   result.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ portName+ "String_Node_Str"+ _eol);
  if (port.isOutput())   result.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ portName+ "String_Node_Str"+ _eol);
  Receiver[][] receiverss;
  if (port.isInput())   receiverss=port.getReceivers();
 else   if (port.isOutput() && actor instanceof CompositeActor)   receiverss=port.getInsideReceivers();
 else   receiverss=new Receiver[0][];
  String directorCall=(actor instanceof CompositeActor ? "String_Node_Str" : "String_Node_Str");
  if (port instanceof PtidesPort)   directorCall=(!port.isInput() && actor instanceof CompositeActor && ((CompositeActor)actor).isOpaque() ? "String_Node_Str" : "String_Node_Str");
  String localReceiver=(port.isInput() ? "String_Node_Str" : "String_Node_Str");
  for (  Receiver[] receivers : receiverss) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    int bar=0;
    for (    Receiver receiver : receivers) {
      String typeReceiver=receiver.getClass().getSimpleName();
      if (typeReceiver.compareTo("String_Node_Str") == 0)       typeReceiver="String_Node_Str";
      String receiverName=portName + "String_Node_Str" + foo+ "String_Node_Str"+ bar;
      result.append("String_Node_Str" + typeReceiver + "String_Node_Str"+ receiverName+ "String_Node_Str"+ typeReceiver+ "String_Node_Str"+ _eol);
      result.append(receiverName + "String_Node_Str" + portName+ "String_Node_Str"+ _eol);
      if (receiver instanceof PtidesReceiver) {
        result.append(receiverName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ directorCall+ "String_Node_Str"+ sanitizedActorName+ "String_Node_Str"+ _eol);
      }
 else       if (receiver instanceof DEReceiver) {
        result.append(receiverName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ directorCall+ "String_Node_Str"+ sanitizedActorName+ "String_Node_Str"+ _eol);
      }
      result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ receiverName+ "String_Node_Str"+ _eol);
      bar++;
    }
    result.append("String_Node_Str" + portName + "String_Node_Str"+ localReceiver+ "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    foo++;
  }
  if (port.isInput() && actor instanceof CompositeActor)   for (foo=0; foo < port.getWidthInside(); foo++) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    result.append("String_Node_Str" + portName + "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
  }
  if (port.isOutput())   for (foo=0; foo < port.getWidth(); foo++) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    result.append("String_Node_Str" + portName + "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
  }
  return result.toString();
}

Fixed version (ground truth):
/** 
 * Generate the code of the declaration of an IOPort (or a subclass) Initialize all its dependencies (container, widths ...) In this base class we deal with all the known kinds of ports, however ideally we should create an adapter for each type of port. There are essentially four types of ports : - input/output - from a composite/atomic actor The creation of the receivers relies on this distinction.
 * @return the port declaration to include in the actor constructor
 * @exception IllegalActionException if the getWidth or getWidthInsidethrows an exception 
 */
public String generatePortDeclaration() throws IllegalActionException {
  StringBuffer result=new StringBuffer();
  TemplateParser tParser=getTemplateParser();
  ProgramCodeGenerator codeGenerator=getCodeGenerator();
  ptolemy.actor.IOPort port=(ptolemy.actor.IOPort)getComponent();
  String portName=port.getName();
  String typePort=port.getClass().getSimpleName();
  if (port instanceof ParameterPort || port instanceof PubSubPort || port instanceof ModalBasePort)   typePort="String_Node_Str";
  NamedObj actor=port.getContainer();
  String sanitizedActorName=CodeGeneratorAdapter.generateName(actor);
  if (!port.isInsideConnected() && !port.isOutsideConnected())   return "String_Node_Str";
  result.append(portName + "String_Node_Str" + typePort+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isInsideConnected()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isOutsideConnected()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isInput()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isOutput()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.isMultiport()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.getWidth()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.getWidthInside()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.numberOfSinks()+ "String_Node_Str"+ _eol);
  result.append(portName + "String_Node_Str" + port.numberOfSources()+ "String_Node_Str"+ _eol);
  Parameter parameter=(Parameter)((NamedObj)port).getAttribute("String_Node_Str");
  Double ioPortDelayOffset=null;
  if (parameter != null) {
    Token token=parameter.getToken();
    if (token instanceof DoubleToken) {
      ioPortDelayOffset=((DoubleToken)token).doubleValue();
    }
 else     if (token instanceof ArrayToken) {
      ioPortDelayOffset=((DoubleToken)((ArrayToken)token).getElement(0)).doubleValue();
    }
  }
  if (ioPortDelayOffset != null)   result.append(portName + "String_Node_Str" + ioPortDelayOffset.doubleValue()+ "String_Node_Str"+ _eol);
  if (port instanceof MirrorPort) {
    MirrorPort mport=(MirrorPort)port;
    MirrorPort associatedPort=mport.getAssociatedPort();
    String accessorAssociatedPort=CodeGeneratorAdapter.generateName(associatedPort.getContainer()) + "String_Node_Str" + associatedPort.getName()+ "String_Node_Str";
    result.append("String_Node_Str" + portName + "String_Node_Str"+ accessorAssociatedPort+ "String_Node_Str"+ _eol);
    if (mport instanceof PtidesPort) {
      PtidesPort ptidesPort=(PtidesPort)mport;
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((BooleanToken)ptidesPort.actuateAtEventTimestamp.getToken()).booleanValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.deviceDelay.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.deviceDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      result.append("String_Node_Str" + portName + "String_Node_Str"+ ((BooleanToken)ptidesPort.isNetworkPort.getToken()).booleanValue()+ "String_Node_Str"+ _eol);
      if (ptidesPort.isNetworkReceiverPort() || ptidesPort.isNetworkTransmitterPort()) {
        result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.networkDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
        result.append("String_Node_Str" + portName + "String_Node_Str"+ ((DoubleToken)ptidesPort.sourcePlatformDelayBound.getToken()).doubleValue()+ "String_Node_Str"+ _eol);
      }
    }
  }
  if (port instanceof TypedIOPort) {
    TypedIOPort typedPort=(TypedIOPort)port;
    String type=codeGenerator.codeGenType(typedPort.getType());
    if (type.contains("String_Node_Str")) {
      result.append(portName + "String_Node_Str" + _eol);
      tParser.addNewTypesUsed("String_Node_Str");
      for (      String typ : type.split("String_Node_Str")) {
        tParser.addNewTypesUsed(typ);
      }
    }
 else {
      result.append(portName + "String_Node_Str" + type+ "String_Node_Str"+ _eol);
      tParser.addNewTypesUsed(type);
    }
  }
  int foo=0;
  if (port.isInput())   result.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ portName+ "String_Node_Str"+ _eol);
  if (port.isOutput())   result.append("String_Node_Str" + sanitizedActorName + "String_Node_Str"+ portName+ "String_Node_Str"+ _eol);
  Receiver[][] receiverss;
  if (port.isInput())   receiverss=port.getReceivers();
 else   if (port.isOutput() && actor instanceof CompositeActor)   receiverss=port.getInsideReceivers();
 else   receiverss=new Receiver[0][];
  String directorCall=(actor instanceof CompositeActor ? "String_Node_Str" : "String_Node_Str");
  if (port instanceof PtidesPort)   directorCall=(!port.isInput() && actor instanceof CompositeActor && ((CompositeActor)actor).isOpaque() ? "String_Node_Str" : "String_Node_Str");
  String localReceiver=(port.isInput() ? "String_Node_Str" : "String_Node_Str");
  for (  Receiver[] receivers : receiverss) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    int bar=0;
    for (    Receiver receiver : receivers) {
      String typeReceiver=receiver.getClass().getSimpleName();
      if (typeReceiver.compareTo("String_Node_Str") == 0)       typeReceiver="String_Node_Str";
      String receiverName=portName + "String_Node_Str" + foo+ "String_Node_Str"+ bar;
      result.append("String_Node_Str" + typeReceiver + "String_Node_Str"+ receiverName+ "String_Node_Str"+ typeReceiver+ "String_Node_Str"+ _eol);
      result.append(receiverName + "String_Node_Str" + portName+ "String_Node_Str"+ _eol);
      if (receiver instanceof PtidesReceiver) {
        result.append(receiverName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ directorCall+ "String_Node_Str"+ sanitizedActorName+ "String_Node_Str"+ _eol);
      }
 else       if (receiver instanceof DEReceiver) {
        result.append(receiverName + "String_Node_Str" + sanitizedActorName+ "String_Node_Str"+ directorCall+ "String_Node_Str"+ sanitizedActorName+ "String_Node_Str"+ _eol);
      }
      result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ receiverName+ "String_Node_Str"+ _eol);
      bar++;
    }
    result.append("String_Node_Str" + portName + "String_Node_Str"+ localReceiver+ "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    foo++;
  }
  if (port.isInput() && actor instanceof CompositeActor)   for (foo=0; foo < port.getWidthInside(); foo++) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    result.append("String_Node_Str" + portName + "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
  }
  if (port.isOutput())   for (foo=0; foo < port.getWidth(); foo++) {
    result.append("String_Node_Str" + portName + "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
    result.append("String_Node_Str" + portName + "String_Node_Str"+ portName+ "String_Node_Str"+ foo+ "String_Node_Str"+ _eol);
  }
  return result.toString();
}