Program: 75763
Project: 75763
Buggy source:
/** 
 * Generate Giotto code for this model. NOTE: This is highly preliminary.
 */
public void generateGiottoCode() throws IllegalActionException {
  try {
    String file=((StringToken)filename.getToken()).stringValue();
    FileOutputStream fout=new FileOutputStream(file);
    PrintStream pout=new PrintStream(fout);
    pout.println("String_Node_Str");
    TypedCompositeActor container=(TypedCompositeActor)getContainer();
    Iterator inPorts=container.inputPortList().iterator();
    while (inPorts.hasNext()) {
      TypedIOPort port=(TypedIOPort)inPorts.next();
      String driverName=port.getName() + "String_Node_Str";
      pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ driverName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    Iterator outPorts=container.outputPortList().iterator();
    while (outPorts.hasNext()) {
      TypedIOPort port=(TypedIOPort)outPorts.next();
      String driverName=port.getName() + "String_Node_Str";
      pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ driverName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    Iterator actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      outPorts=actor.outputPortList().iterator();
      while (outPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)outPorts.next();
        String sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
        pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ sanitizedPortName+ "String_Node_Str"+ sanitizedPortName+ "String_Node_Str");
      }
    }
    actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      String taskName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      pout.print("String_Node_Str" + taskName + "String_Node_Str");
      inPorts=actor.inputPortList().iterator();
      String inPortsNames="String_Node_Str";
      String outPortsNames="String_Node_Str";
      while (inPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)inPorts.next();
        inPortsNames+=port.getName();
        pout.print(port.getName());
        if (inPorts.hasNext()) {
          inPortsNames+="String_Node_Str";
          pout.print("String_Node_Str");
        }
      }
      pout.print("String_Node_Str");
      outPorts=actor.outputPortList().iterator();
      while (outPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)outPorts.next();
        String sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
        outPortsNames+=sanitizedPortName;
        pout.print(sanitizedPortName);
        if (outPorts.hasNext()) {
          outPortsNames+="String_Node_Str";
          pout.print("String_Node_Str");
        }
      }
      pout.println("String_Node_Str");
      pout.println("String_Node_Str" + taskName + "String_Node_Str"+ inPortsNames+ "String_Node_Str"+ outPortsNames+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    actors=container.deepEntityList().iterator();
    String driverParas, outParas, typedOutParas;
    String actorName;
    Director director=((Actor)container).getDirector();
    while (actors.hasNext()) {
      driverParas="String_Node_Str";
      outParas="String_Node_Str";
      typedOutParas="String_Node_Str";
      actorName="String_Node_Str";
      TypedActor actor=(TypedActor)actors.next();
      actorName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      pout.print("String_Node_Str" + actorName + "String_Node_Str");
      inPorts=actor.inputPortList().iterator();
      while (inPorts.hasNext()) {
        IOPort thisPort=(IOPort)inPorts.next();
        int directorDepth=((IOPort)thisPort).depthOfDirector(director);
        String sanitizedPortName=StringUtilities.sanitizeName(thisPort.getName(container));
        Iterator sourcePorts=thisPort.sourcePortList(directorDepth).iterator();
        while (sourcePorts.hasNext()) {
          IOPort port=(IOPort)sourcePorts.next();
          sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
          if (driverParas.length() == 0) {
            driverParas+=sanitizedPortName;
          }
 else {
            driverParas+="String_Node_Str" + sanitizedPortName;
          }
        }
      }
      inPorts=actor.inputPortList().iterator();
      while (inPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)inPorts.next();
        if (outParas == "String_Node_Str") {
          typedOutParas+=port.getType() + "String_Node_Str" + port.getName();
          outParas+=port.getName();
        }
 else {
          typedOutParas+="String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName();
          outParas+="String_Node_Str" + port.getName();
        }
      }
      pout.println(driverParas + "String_Node_Str" + typedOutParas+ "String_Node_Str");
      pout.println("String_Node_Str" + actorName + "String_Node_Str"+ driverParas+ "String_Node_Str");
      pout.println("String_Node_Str" + actorName + "String_Node_Str"+ driverParas+ "String_Node_Str"+ outParas+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    Iterator topOutPorts=container.outputPortList().iterator();
    String outputName="String_Node_Str";
    String sanitizedPortName="String_Node_Str";
    while (topOutPorts.hasNext()) {
      driverParas="String_Node_Str";
      outParas="String_Node_Str";
      typedOutParas="String_Node_Str";
      outputName="String_Node_Str";
      TypedIOPort port=(TypedIOPort)topOutPorts.next();
      outputName=StringUtilities.sanitizeName(port.getName(container));
      pout.print("String_Node_Str" + outputName + "String_Node_Str");
      outParas+=port.getName();
      typedOutParas+=port.getType() + "String_Node_Str" + port.getName();
      Iterator portConnected=port.deepInsidePortList().iterator();
      if (port.deepInsidePortList().size() != 0) {
        while (portConnected.hasNext()) {
          TypedIOPort outPort=(TypedIOPort)portConnected.next();
          sanitizedPortName=StringUtilities.sanitizeName(outPort.getName(container));
          if (outPort.isOutput()) {
            if (driverParas.length() == 0) {
              driverParas+=sanitizedPortName;
            }
 else {
              driverParas+="String_Node_Str" + sanitizedPortName;
            }
          }
        }
      }
      pout.println(driverParas + "String_Node_Str" + typedOutParas+ "String_Node_Str");
      pout.println("String_Node_Str" + outputName + "String_Node_Str"+ driverParas+ "String_Node_Str");
      pout.println("String_Node_Str" + outputName + "String_Node_Str"+ driverParas+ "String_Node_Str"+ outParas+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    String containerName=container.getName();
    double periodValue=((DoubleToken)period.getToken()).doubleValue();
    int actorFreq=0;
    int actFreq=0;
    pout.println("String_Node_Str" + containerName + "String_Node_Str");
    pout.println("String_Node_Str" + containerName + "String_Node_Str"+ periodValue+ "String_Node_Str");
    topOutPorts=container.outputPortList().iterator();
    while (topOutPorts.hasNext()) {
      outputName="String_Node_Str";
      TypedIOPort port=(TypedIOPort)topOutPorts.next();
      outputName=StringUtilities.sanitizeName(port.getName(container));
      Iterator portConnected=port.deepInsidePortList().iterator();
      if (port.deepInsidePortList().size() != 0) {
        while (portConnected.hasNext()) {
          TypedIOPort outPort=(TypedIOPort)portConnected.next();
          actorFreq=1;
          pout.println("String_Node_Str" + actorFreq + "String_Node_Str"+ outputName+ "String_Node_Str"+ outputName+ "String_Node_Str");
        }
      }
    }
    actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      actorName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      Parameter actorFreqPara=(Parameter)((NamedObj)actor).getAttribute("String_Node_Str");
      actorFreq=((IntToken)actorFreqPara.getToken()).intValue();
      pout.println("String_Node_Str" + actorFreq + "String_Node_Str"+ actorName+ "String_Node_Str"+ actorName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    pout.println("String_Node_Str");
  }
 catch (  IOException ex) {
    throw new IllegalActionException(this,ex.getMessage());
  }
}

Fixed version (ground truth):
/** 
 * Generate Giotto code for this model. NOTE: This is highly preliminary.
 */
public void generateGiottoCode() throws IllegalActionException {
  try {
    String file=((StringToken)filename.getToken()).stringValue();
    FileOutputStream fout=new FileOutputStream(file);
    PrintStream pout=new PrintStream(fout);
    pout.println("String_Node_Str");
    TypedCompositeActor container=(TypedCompositeActor)getContainer();
    Iterator inPorts=container.inputPortList().iterator();
    while (inPorts.hasNext()) {
      TypedIOPort port=(TypedIOPort)inPorts.next();
      String driverName=port.getName() + "String_Node_Str";
      pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ driverName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    Iterator outPorts=container.outputPortList().iterator();
    while (outPorts.hasNext()) {
      TypedIOPort port=(TypedIOPort)outPorts.next();
      String driverName=port.getName() + "String_Node_Str";
      pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName()+ "String_Node_Str"+ driverName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    Iterator actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      outPorts=actor.outputPortList().iterator();
      while (outPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)outPorts.next();
        String sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
        pout.println("String_Node_Str" + port.getType() + "String_Node_Str"+ sanitizedPortName+ "String_Node_Str"+ sanitizedPortName+ "String_Node_Str");
      }
    }
    actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      String taskName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      pout.print("String_Node_Str" + taskName + "String_Node_Str");
      inPorts=actor.inputPortList().iterator();
      String inPortsNames="String_Node_Str";
      String outPortsNames="String_Node_Str";
      while (inPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)inPorts.next();
        inPortsNames+=port.getName();
        pout.print(port.getName());
        if (inPorts.hasNext()) {
          inPortsNames+="String_Node_Str";
          pout.print("String_Node_Str");
        }
      }
      pout.print("String_Node_Str");
      outPorts=actor.outputPortList().iterator();
      while (outPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)outPorts.next();
        String sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
        outPortsNames+=sanitizedPortName;
        pout.print(sanitizedPortName);
        if (outPorts.hasNext()) {
          outPortsNames+="String_Node_Str";
          pout.print("String_Node_Str");
        }
      }
      pout.println("String_Node_Str");
      pout.println("String_Node_Str" + taskName + "String_Node_Str"+ inPortsNames+ "String_Node_Str"+ outPortsNames+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    actors=container.deepEntityList().iterator();
    String driverParas, outParas, typedOutParas;
    String actorName;
    while (actors.hasNext()) {
      driverParas="String_Node_Str";
      outParas="String_Node_Str";
      typedOutParas="String_Node_Str";
      actorName="String_Node_Str";
      TypedActor actor=(TypedActor)actors.next();
      actorName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      pout.print("String_Node_Str" + actorName + "String_Node_Str");
      inPorts=actor.inputPortList().iterator();
      while (inPorts.hasNext()) {
        IOPort thisPort=(IOPort)inPorts.next();
        String sanitizedPortName=StringUtilities.sanitizeName(thisPort.getName(container));
        Iterator sourcePorts=thisPort.sourcePortList().iterator();
        while (sourcePorts.hasNext()) {
          IOPort port=(IOPort)sourcePorts.next();
          sanitizedPortName=StringUtilities.sanitizeName(port.getName(container));
          if (driverParas.length() == 0) {
            driverParas+=sanitizedPortName;
          }
 else {
            driverParas+="String_Node_Str" + sanitizedPortName;
          }
        }
      }
      inPorts=actor.inputPortList().iterator();
      while (inPorts.hasNext()) {
        TypedIOPort port=(TypedIOPort)inPorts.next();
        if (outParas == "String_Node_Str") {
          typedOutParas+=port.getType() + "String_Node_Str" + port.getName();
          outParas+=port.getName();
        }
 else {
          typedOutParas+="String_Node_Str" + port.getType() + "String_Node_Str"+ port.getName();
          outParas+="String_Node_Str" + port.getName();
        }
      }
      pout.println(driverParas + "String_Node_Str" + typedOutParas+ "String_Node_Str");
      pout.println("String_Node_Str" + actorName + "String_Node_Str"+ driverParas+ "String_Node_Str");
      pout.println("String_Node_Str" + actorName + "String_Node_Str"+ driverParas+ "String_Node_Str"+ outParas+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    Iterator topOutPorts=container.outputPortList().iterator();
    String outputName="String_Node_Str";
    String sanitizedPortName="String_Node_Str";
    while (topOutPorts.hasNext()) {
      driverParas="String_Node_Str";
      outParas="String_Node_Str";
      typedOutParas="String_Node_Str";
      outputName="String_Node_Str";
      TypedIOPort port=(TypedIOPort)topOutPorts.next();
      outputName=StringUtilities.sanitizeName(port.getName(container));
      pout.print("String_Node_Str" + outputName + "String_Node_Str");
      outParas+=port.getName();
      typedOutParas+=port.getType() + "String_Node_Str" + port.getName();
      Iterator portConnected=port.deepInsidePortList().iterator();
      if (port.deepInsidePortList().size() != 0) {
        while (portConnected.hasNext()) {
          TypedIOPort outPort=(TypedIOPort)portConnected.next();
          sanitizedPortName=StringUtilities.sanitizeName(outPort.getName(container));
          if (outPort.isOutput()) {
            if (driverParas.length() == 0) {
              driverParas+=sanitizedPortName;
            }
 else {
              driverParas+="String_Node_Str" + sanitizedPortName;
            }
          }
        }
      }
      pout.println(driverParas + "String_Node_Str" + typedOutParas+ "String_Node_Str");
      pout.println("String_Node_Str" + outputName + "String_Node_Str"+ driverParas+ "String_Node_Str");
      pout.println("String_Node_Str" + outputName + "String_Node_Str"+ driverParas+ "String_Node_Str"+ outParas+ "String_Node_Str");
      pout.println("String_Node_Str");
    }
    String containerName=container.getName();
    double periodValue=((DoubleToken)period.getToken()).doubleValue();
    int actorFreq=0;
    int actFreq=0;
    pout.println("String_Node_Str" + containerName + "String_Node_Str");
    pout.println("String_Node_Str" + containerName + "String_Node_Str"+ periodValue+ "String_Node_Str");
    topOutPorts=container.outputPortList().iterator();
    while (topOutPorts.hasNext()) {
      outputName="String_Node_Str";
      TypedIOPort port=(TypedIOPort)topOutPorts.next();
      outputName=StringUtilities.sanitizeName(port.getName(container));
      Iterator portConnected=port.deepInsidePortList().iterator();
      if (port.deepInsidePortList().size() != 0) {
        while (portConnected.hasNext()) {
          TypedIOPort outPort=(TypedIOPort)portConnected.next();
          Nameable actor=outPort.getContainer();
          if (actor instanceof Actor) {
            Parameter actorFreqPara=(Parameter)((NamedObj)actor).getAttribute("String_Node_Str");
            actorFreq=((IntToken)actorFreqPara.getToken()).intValue();
          }
          pout.println("String_Node_Str" + actorFreq + "String_Node_Str"+ outputName+ "String_Node_Str"+ outputName+ "String_Node_Str");
        }
      }
    }
    actors=container.deepEntityList().iterator();
    while (actors.hasNext()) {
      TypedActor actor=(TypedActor)actors.next();
      actorName=StringUtilities.sanitizeName(((NamedObj)actor).getName(container));
      Parameter actorFreqPara=(Parameter)((NamedObj)actor).getAttribute("String_Node_Str");
      actorFreq=((IntToken)actorFreqPara.getToken()).intValue();
      pout.println("String_Node_Str" + actorFreq + "String_Node_Str"+ actorName+ "String_Node_Str"+ actorName+ "String_Node_Str");
    }
    pout.println("String_Node_Str");
    pout.println("String_Node_Str");
  }
 catch (  IOException ex) {
    throw new IllegalActionException(this,ex.getMessage());
  }
}