Ejemplo n.º 1
0
  /**
   * Return the type constraints of this actor. The type constraint is that the type of the output
   * ports is no less than the type of the fields of the output RecordToken.
   *
   * @return a list of Inequality.
   */
  public Set<Inequality> typeConstraints() {
    Object[] portArray = outputPortList().toArray();
    int size = portArray.length;
    String[] labels = new String[size];
    Type[] types = new Type[size];

    // form the declared type for the output port
    for (int i = 0; i < size; i++) {
      labels[i] = ((Port) portArray[i]).getName();
      types[i] = BaseType.GENERAL;
    }

    RecordType declaredType = new RecordType(labels, types);

    input.setTypeAtMost(declaredType);

    // set the constraints between record fields and output ports
    Set<Inequality> constraints = new HashSet<Inequality>();

    // since the input port has a clone of the above RecordType, need to
    // get the type from the input port.
    //   RecordType inputTypes = (RecordType)input.getType();
    Iterator outputPorts = outputPortList().iterator();

    while (outputPorts.hasNext()) {
      TypedIOPort outputPort = (TypedIOPort) outputPorts.next();
      String label = outputPort.getName();
      Inequality inequality = new Inequality(new PortFunction(label), outputPort.getTypeTerm());
      constraints.add(inequality);
    }

    return constraints;
  }