Program: 72543
Project: 72543
Buggy source:
/** 
 * Generate the code for the firing of actors. In this base class, it is attempted to fire all the actors once. In subclasses such as the adapters for SDF and Giotto directors, the firings of actors observe the associated schedule. In addition, some special handling is needed, e.g., the iteration limit in SDF and time advancement in Giotto.
 * @return The generated code.
 * @exception IllegalActionException If the adapter associated with an actor throws it while generating fire code for the actor.
 */
@Override public String generateFMIMA() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  NamedProgramCodeGeneratorAdapter adapter=(NamedProgramCodeGeneratorAdapter)getAdapter(getComponent());
  Iterator<?> actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  code.append(getCodeGenerator().comment("String_Node_Str" + _eol + "String_Node_Str"+ adapter.getComponent().getName()));
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  codeStream.appendCodeBlock("String_Node_Str");
  code.append(processCode(codeStream.toString()));
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.fmuFile.asFile().toString().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.fmuFile.asFile().toString().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.getName()+ "String_Node_Str");
  }
  HashMap<Node,FMIScalarVariable> node2Scalar=new HashMap<Node,FMIScalarVariable>();
  HashMap<Node,TypedIOPort> node2Port=new HashMap<Node,TypedIOPort>();
  HashMap<TypedIOPort,FMIScalarVariable> port2Scalar=new HashMap<TypedIOPort,FMIScalarVariable>();
  HashMap<TypedIOPort,Node> port2Node=new HashMap<TypedIOPort,Node>();
  DirectedGraph graph=new DirectedGraph();
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    for (    TypedIOPort port : actor.portList()) {
      for (      FMIScalarVariable scalar : actor.getScalarVariables()) {
        if ((scalar.causality == Causality.input || scalar.causality == Causality.output) && scalar.name.equals(port.getName())) {
          Node node=new Node(port);
          port2Scalar.put(port,scalar);
          node2Scalar.put(node,scalar);
          port2Node.put(port,node);
          node2Port.put(node,port);
          graph.addNode(node);
        }
      }
    }
  }
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  int connectionNumber=0;
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    for (    TypedIOPort output : actor.outputPortList()) {
      FMIScalarVariable scalar=port2Scalar.get(output);
      List<FMIScalarVariable> inputDependencies=actor.getInputDependencyList(scalar);
      if (inputDependencies != null) {
        for (        FMIScalarVariable inputScalar : inputDependencies) {
          Node source=null;
          Node sink=port2Node.get(output);
          for (          TypedIOPort port : actor.inputPortList()) {
            if (port.getName().equals(inputScalar.name))             source=port2Node.get(port);
          }
          graph.addEdge(source,sink);
        }
      }
    }
    for (    TypedIOPort input : actor.inputPortList()) {
      Node sink=port2Node.get(input);
      List<TypedIOPort> connected_ports=input.connectedPortList();
      for (      TypedIOPort output : connected_ports) {
        Node source=port2Node.get(output);
        graph.addEdge(source,sink);
        connectionNumber++;
      }
    }
  }
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  Collection<Node> nodeCollection=graph.nodes();
  if (graph.isAcyclic() == false) {
    throw new IllegalActionException(adapter.getComponent(),"String_Node_Str");
  }
  List sortedGraph=graph.topologicalSort(nodeCollection);
  int connectionIndex=0;
  for (int i=0; i < connectionNumber; i++) {
    Node portSourceNode=(Node)sortedGraph.get(0);
    Node portSinkNode=(Node)sortedGraph.get(1);
    sortedGraph.remove(portSourceNode);
    sortedGraph.remove(portSinkNode);
    FMIScalarVariable sourceScalar=node2Scalar.get(portSourceNode);
    FMIScalarVariable sinkScalar=node2Scalar.get(portSinkNode);
    ptolemy.actor.lib.fmi.FMUImport sourceActor=(ptolemy.actor.lib.fmi.FMUImport)node2Port.get(portSourceNode).getContainer();
    ptolemy.actor.lib.fmi.FMUImport sinkActor=(ptolemy.actor.lib.fmi.FMUImport)node2Port.get(portSinkNode).getContainer();
    String fmuSourceName=sourceActor.getName();
    String fmuSinkName=sinkActor.getName();
    String sourceType="String_Node_Str";
    String sinkType="String_Node_Str";
    if (sourceScalar.type instanceof FMIBooleanType) {
      sourceType="String_Node_Str";
    }
 else     if (sourceScalar.type instanceof FMIIntegerType) {
      sourceType="String_Node_Str";
    }
 else     if (sourceScalar.type instanceof FMIRealType) {
      sourceType="String_Node_Str";
    }
 else     if (sourceScalar.type instanceof FMIStringType) {
      sourceType="String_Node_Str";
    }
    if (sinkScalar.type instanceof FMIBooleanType) {
      sinkType="String_Node_Str";
    }
 else     if (sinkScalar.type instanceof FMIIntegerType) {
      sinkType="String_Node_Str";
    }
 else     if (sinkScalar.type instanceof FMIRealType) {
      sinkType="String_Node_Str";
    }
 else     if (sinkScalar.type instanceof FMIStringType) {
      sinkType="String_Node_Str";
    }
    code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ fmuSourceName+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ fmuSourceName+ "String_Node_Str"+ sourceScalar.valueReference+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ sourceType+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ fmuSinkName+ "String_Node_Str");
    code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ fmuSinkName+ "String_Node_Str"+ sinkScalar.valueReference+ "String_Node_Str");
    code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ sinkType+ "String_Node_Str");
    connectionIndex++;
  }
  codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  codeStream.appendCodeBlock("String_Node_Str");
  code.append(processCode(codeStream.toString()));
  code.append(getCodeGenerator().comment("String_Node_Str"));
  return code.toString();
}

Fixed version (ground truth):
/** 
 * Generate the code for the firing of actors. In this base class, it is attempted to fire all the actors once. In subclasses such as the adapters for SDF and Giotto directors, the firings of actors observe the associated schedule. In addition, some special handling is needed, e.g., the iteration limit in SDF and time advancement in Giotto.
 * @return The generated code.
 * @exception IllegalActionException If the adapter associated with an actor throws it while generating fire code for the actor.
 */
@Override public String generateFMIMA() throws IllegalActionException {
  StringBuffer code=new StringBuffer();
  NamedProgramCodeGeneratorAdapter adapter=(NamedProgramCodeGeneratorAdapter)getAdapter(getComponent());
  Iterator<?> actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  code.append(getCodeGenerator().comment("String_Node_Str" + _eol + "String_Node_Str"+ adapter.getComponent().getName()));
  CodeStream codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  codeStream.appendCodeBlock("String_Node_Str");
  code.append(processCode(codeStream.toString()));
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.fmuFile.asFile().toString().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.fmuFile.asFile().toString().replace("String_Node_Str","String_Node_Str")+ "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str");
    code.append("String_Node_Str" + actor.getName() + "String_Node_Str"+ actor.getName()+ "String_Node_Str");
  }
  HashMap<Node,FMIScalarVariable> node2Scalar=new HashMap<Node,FMIScalarVariable>();
  HashMap<Node,TypedIOPort> node2Port=new HashMap<Node,TypedIOPort>();
  HashMap<TypedIOPort,FMIScalarVariable> port2Scalar=new HashMap<TypedIOPort,FMIScalarVariable>();
  HashMap<TypedIOPort,Node> port2Node=new HashMap<TypedIOPort,Node>();
  DirectedGraph graph=new DirectedGraph();
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    for (    TypedIOPort port : actor.portList()) {
      for (      FMIScalarVariable scalar : actor.getScalarVariables()) {
        if ((scalar.causality == Causality.input || scalar.causality == Causality.output) && scalar.name.equals(port.getName())) {
          Node node=new Node(port);
          port2Scalar.put(port,scalar);
          node2Scalar.put(node,scalar);
          port2Node.put(port,node);
          node2Port.put(node,port);
          graph.addNode(node);
        }
      }
    }
  }
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  while (actors.hasNext()) {
    ptolemy.actor.lib.fmi.FMUImport actor=(ptolemy.actor.lib.fmi.FMUImport)actors.next();
    for (    TypedIOPort output : actor.outputPortList()) {
      FMIScalarVariable scalar=port2Scalar.get(output);
      List<FMIScalarVariable> inputDependencies=actor.getInputDependencyList(scalar);
      if (inputDependencies != null) {
        for (        FMIScalarVariable inputScalar : inputDependencies) {
          Node source=null;
          Node sink=port2Node.get(output);
          for (          TypedIOPort port : actor.inputPortList()) {
            if (port.getName().equals(inputScalar.name))             source=port2Node.get(port);
          }
          graph.addEdge(source,sink);
        }
      }
    }
    for (    TypedIOPort input : actor.inputPortList()) {
      Node sink=port2Node.get(input);
      List<TypedIOPort> connected_ports=input.connectedPortList();
      for (      TypedIOPort output : connected_ports) {
        Node source=port2Node.get(output);
        graph.addEdge(source,sink);
      }
    }
  }
  actors=((CompositeActor)adapter.getComponent().getContainer()).deepEntityList().iterator();
  Collection<Node> nodeCollection=graph.nodes();
  if (graph.isAcyclic() == false) {
    throw new IllegalActionException(adapter.getComponent(),"String_Node_Str");
  }
  List<Node> sortedGraph=graph.topologicalSort(nodeCollection);
  int connectionIndex=0;
  for (  Node sourceNode : sortedGraph) {
    if (node2Port.get(sourceNode).isOutput()) {
      Collection<Node> successors=graph.successors(sourceNode);
      for (      Node sinkNode : successors) {
        FMIScalarVariable sourceScalar=node2Scalar.get(sourceNode);
        FMIScalarVariable sinkScalar=node2Scalar.get(sinkNode);
        ptolemy.actor.lib.fmi.FMUImport sourceActor=(ptolemy.actor.lib.fmi.FMUImport)node2Port.get(sourceNode).getContainer();
        ptolemy.actor.lib.fmi.FMUImport sinkActor=(ptolemy.actor.lib.fmi.FMUImport)node2Port.get(sinkNode).getContainer();
        String fmuSourceName=sourceActor.getName();
        String fmuSinkName=sinkActor.getName();
        String sourceType="String_Node_Str";
        String sinkType="String_Node_Str";
        if (sourceScalar.type instanceof FMIBooleanType) {
          sourceType="String_Node_Str";
        }
 else         if (sourceScalar.type instanceof FMIIntegerType) {
          sourceType="String_Node_Str";
        }
 else         if (sourceScalar.type instanceof FMIRealType) {
          sourceType="String_Node_Str";
        }
 else         if (sourceScalar.type instanceof FMIStringType) {
          sourceType="String_Node_Str";
        }
        if (sinkScalar.type instanceof FMIBooleanType) {
          sinkType="String_Node_Str";
        }
 else         if (sinkScalar.type instanceof FMIIntegerType) {
          sinkType="String_Node_Str";
        }
 else         if (sinkScalar.type instanceof FMIRealType) {
          sinkType="String_Node_Str";
        }
 else         if (sinkScalar.type instanceof FMIStringType) {
          sinkType="String_Node_Str";
        }
        code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ fmuSourceName+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ fmuSourceName+ "String_Node_Str"+ sourceScalar.valueReference+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ sourceType+ "String_Node_Str"+ "String_Node_Str"+ connectionIndex+ "String_Node_Str"+ fmuSinkName+ "String_Node_Str");
        code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ fmuSinkName+ "String_Node_Str"+ sinkScalar.valueReference+ "String_Node_Str");
        code.append("String_Node_Str" + connectionIndex + "String_Node_Str"+ sinkType+ "String_Node_Str");
        connectionIndex++;
      }
    }
  }
  codeStream=_templateParser.getCodeStream();
  codeStream.clear();
  codeStream.appendCodeBlock("String_Node_Str");
  code.append(processCode(codeStream.toString()));
  code.append(getCodeGenerator().comment("String_Node_Str"));
  return code.toString();
}