public boolean areAllActionsGuarded() {
   for (Action action : mActor.getImplementation().getActions()) {
     ActionAnalysis actionAnalysis = new ActionAnalysis(action, mActor);
     if (!action.hasGuard() && !actionAnalysis.isCatchAll()) {
       return false;
     }
   }
   return true;
 }
 public boolean isSingleRateActor() {
   for (Action action : mActor.getImplementation().getActions()) {
     PortSignature portSignature = action.getPortSignature();
     for (PortInstance portInstance : portSignature.getPorts()) {
       if (portSignature.getPortRate(portInstance) > 1) return false;
     }
   }
   return true; // executesIndefinitely();
 }
 /**
  * An actor is a quasi-static actor if 1) it has a tree-structured FSM. 2) all feedback
  * transitions return back to the initial state. 3) a state does not terminate.
  *
  * @return
  */
 private boolean isQuasiStaticActor() {
   ActorSchedule schedule = mActor.getImplementation().getSchedule();
   State initialState = schedule.getInitialState();
   for (Transition transition : initialState.getTransitions()) {
     State dstState = transition.getTargetState();
     List<State> visitedStates = new ArrayList<State>();
     visitedStates.add(dstState);
     if (!isQuasiStaticBranch(initialState, dstState, visitedStates)) return false;
   }
   return true;
 }
  private boolean isSingleRateStaticActor() {
    if (!hasStaticSchedule()) return false;

    if (!isSingleRateActor()) return false;
    for (PortInstance portInstance : mActor.getPorts()) {
      List<Action> actions =
          new ArrayList<Action>(getStaticSchedule().getRepeatedPhase().getFlatSequence());
      assert (actions != null);
      if (!getPortAnalysis(portInstance).isActiveInAllActions(actions)) return false;
    }
    return true;
  }
 public PortAnalysis getPortAnalysis(String name) {
   PortInstance portInstance = null;
   for (PortInstance p : mActor.getPorts()) {
     if (p.getName().equals(name)) {
       portInstance = p;
       break;
     }
   }
   if (portInstance != null) {
     assert (mPortMap.get(portInstance) != null);
     return mPortMap.get(portInstance);
   }
   return null;
 }
 /**
  * Checks if the guards of those non-deterministic actions matches the following format. Guards
  * are of the form <M "op" C [ (and/or) M "op" C]> where M is a port variable, "op" is "=, !=, <=,
  * >=, <, >" and C is a constant.
  */
 public boolean areNonDeterministicStatesSimplyGuarded() {
   ActorSchedule schedule = mActor.getImplementation().getSchedule();
   for (State state : schedule.getStates()) {
     if (state.getTransitions().size() > 1) {
       for (Transition transition : state.getTransitions()) {
         Action action = transition.getAction();
         if (!action.hasGuard()) return false;
         Guard guard = action.getGuard();
         Map<InputLookAhead, UnionOfDisjointIntervals> modeSet = guard.matchScenarioAwareGuard();
         if (modeSet == null) return false;
       }
     }
   }
   return true;
 }
  /**
   * An actor is a multi-rate static actor (SDF) if 1.all ports are active in all actions in the
   * periodic phase 2.all actions in the periodic phase have the same port signature
   *
   * @return true if it is an SDF actor and false otherwise.
   */
  private boolean isMultiRateStaticActor() {
    if (!hasStaticSchedule()) return false;

    // check if all ports are active in the periodic phase
    List<Action> actions =
        new ArrayList<Action>(getStaticSchedule().getRepeatedPhase().getFlatSequence());
    for (PortInstance portInstance : mActor.getPorts()) {
      if (!getPortAnalysis(portInstance).isActiveInAllActions(actions)) return false;
    }

    // Check if all actions in the periodic phase have the same port signatures
    PortSignature refPortSignature = null;
    for (Action action : getStaticSchedule().getRepeatedPhase().getFlatSequence()) {
      if (refPortSignature == null) refPortSignature = action.getPortSignature();
      else {
        if (refPortSignature.isSubsetOf(action.getPortSignature())
            && action.getPortSignature().isSubsetOf(refPortSignature)) continue;
        else return false;
      }
    }
    return executesIndefinitely();
  }
 /**
  * A dynamic actor has input-dependent behavior. It is assumed now that any actor which has
  * implementation is dynamic. But this can be a broad definition.
  *
  * @return TODO: define a dynamic actor.
  */
 private boolean isDynamicActor() {
   return mActor.hasImplementation();
 }
  public GenericActorAnalysis(ActorInstance actor, ActorAnalysis delegate) {
    mActor = actor;
    actorAnalysis = delegate;
    mActorType = ActorInstanceType.UNCLASSIFIED;

    stateSize = new Integer(0);
    executionTime = new Integer(0);
    for (PortInstance portInstance : mActor.getPorts()) {
      PortAnalysis portAnalysis = new PortAnalysis(portInstance);
      mPortMap.put(portInstance, portAnalysis);
    }

    if (actorAnalysis != null) {
      for (Action action : actor.getImplementation().getActions()) {
        ActionAnalysis actionAnalysis = new ActionAnalysis(action, actor);
        mActionMap.put(action, actionAnalysis);
      }
    }

    // Parse annotations
    if (mActor.hasAnnotation("ActorProperty")) {
      // Set execution time
      String time = mActor.getAnnotationArgumentValue("ActorProperty", "WCET");
      if (time != null) executionTime = new Integer(time);

      // Set state size
      String size = mActor.getAnnotationArgumentValue("ActorProperty", "StateSize");
      if (size != null) stateSize = new Integer(size);

      // Set actor instance type
      String type = mActor.getAnnotationArgumentValue("ActorProperty", "Type");
      if (type != null) {
        typeAnnotated = true;
        if (type.equalsIgnoreCase("HSDF")) {
          mActorType = ActorInstanceType.SINGLE_RATE_STATIC;
        } else if (type.equalsIgnoreCase("SDF")) {
          mActorType = ActorInstanceType.MULTI_RATE_STATIC;
        } else if (type.equalsIgnoreCase("CSDF")) {
          mActorType = ActorInstanceType.CYCLO_STATIC;
        } else typeAnnotated = false;
      }

      // Set action execution times
      try {
        String actionProperties =
            mActor.getAnnotationArgumentValue("ActorProperty", "ActionProperty");
        if (typeAnnotated && actionProperties == null)
          throw new NullPointerException(
              "ActionProperty tag must exist " + "if actor type is annotated with HSDF/SDF/CSDF.");

        if (typeAnnotated && actionProperties != null) {
          for (String actionProperty : actionProperties.split(";")) {
            String actionPropertyPair[] = actionProperty.split(":");
            if (actionPropertyPair.length != 2)
              throw new Exception(
                  "ActionProperty tag syntax error. "
                      + "Use Eg. ActionProperty=\"action1:WCET=2, p1=1, p2=3;action2:WCET=1, p1=0, p2=4\"");
            AnnotatedActionProperty aap = new AnnotatedActionProperty(actionPropertyPair[0]);
            for (String property : actionPropertyPair[1].split(",")) {
              String propertyPair[] = property.split("=");
              if (propertyPair[0].equalsIgnoreCase("WCET"))
                aap.executionTime = new Integer(propertyPair[1]);
              else aap.portRates.put(propertyPair[0], new Integer(propertyPair[1]));
            }
            annotatedActionProperties.add(aap);
          }
          // Check if all ports have a rate in all ActionProperties
          for (AnnotatedActionProperty aap : annotatedActionProperties) {
            for (PortInstance p : getActor().getPorts()) {
              if (aap.portRates.get(p.getName()) == null)
                throw new Exception(
                    "Type annotated actor '"
                        + p.getActor().getInstanceName()
                        + "' does not have rate for port '"
                        + p.getName()
                        + "'.");
            }
          }
        }
      } catch (Exception e) {
        System.out.println(e.getMessage());
        System.exit(1);
      }
    }

    if (!typeAnnotated && actorAnalysis != null) {
      if (isSingleRateStaticActor()) mActorType = ActorInstanceType.SINGLE_RATE_STATIC;
      else if (isMultiRateStaticActor()) mActorType = ActorInstanceType.MULTI_RATE_STATIC;
      else if (isCycloStaticActor()) mActorType = ActorInstanceType.CYCLO_STATIC;
      else if (isQuasiStaticActor()) mActorType = ActorInstanceType.QUASI_STATIC;
      else if (isDynamicActor()) mActorType = ActorInstanceType.DYNAMIC;
    }
  }