Logo Search packages:      
Sourcecode: maria version File versions

bool Net::addSyncTrans ( const class Printer printer  )  [private]

Create fused transitions for all sync transitions in all subnets

Parameters:
printer The printer object for diagnostic output
Returns:
true if the operation succeeded

flag: did the operation succeed?

buffer for instantiated transition names

the callee transition

the instantiated transition where all the children are fused

Definition at line 612 of file Net.C.

References Transition::addChild(), addChild(), addPlaces(), addTransition(), StringBuffer::append(), Transition::changeParent(), StringBuffer::chop(), StringBuffer::copy(), StringBuffer::create(), Transition::fuse(), Transition::getChild(), StringBuffer::getLength(), Transition::getLocalIndex(), Transition::getName(), Transition::getNet(), Transition::getNumChildren(), getNumChildren(), Transition::getNumParents(), Transition::getParent(), StringBuffer::getString(), Transition::isUnifiable(), myCallees, myChildren, myNumCallees, myNumChildren, myNumTransitions, myParent, myTransitionMap, and myTransitions.

Referenced by prepareModular().

{
  /** flag: did the operation succeed? */
  bool ok = true;

  unsigned i;
  if (myParent) {
    // copy the referred places from the parent nets
    for (i = myNumTransitions; i--; )
      addPlaces (*myTransitions[i]);
    for (i = myNumCallees; i--; )
      if (myCallees[i]->getNumChildren ())
      addPlaces (*myCallees[i]);
  }

  // recursively process the subnets
  for (i = myNumChildren; i--; )
    if (!myChildren[i]->addSyncTrans (printer))
      ok = false;

  // adjust myUnif->place numbers in the synchronisation transitions
  if (myParent)
    for (i = myNumTransitions; ok && i--; )
      if (myTransitions[i]->getNumParents () &&
        !myTransitions[i]->isUnifiable (Transition::uIgnore, printer))
      ok = false;

  // instantiate a transition for each synchronisation label

  /** buffer for instantiated transition names */
  class StringBuffer name;

  for (i = myNumCallees; i--; ) {
    /** the callee transition */
    const class Transition& t = *myCallees[i];
    if (!t.getNumChildren ())
      continue;

    // create an unique name
    name.create (0);
    name.append (':', 1), name.append (t.getName ());
    // ensure that the name is unique
    if (myTransitionMap.find (name.getString ()) !=
      myTransitionMap.end ()) {
      const unsigned namelen = name.getLength ();
      for (unsigned k = 0;; k++) {
      name.append (':', 1), name.append (k);
      if (myTransitionMap.find (name.getString ()) ==
          myTransitionMap.end ())
        break;
      name.chop (name.getLength () - namelen);
      }
    }

    /** the instantiated transition where all the children are fused */
    class Transition& trans = addTransition (name.copy (), false);
    for (unsigned p = t.getNumParents (); p--; )
      const_cast<class Transition&>(t.getParent (p)).addChild (trans);

    unsigned k;
    for (k = 0; k < t.getNumChildren (); k++) {
      const class Transition& u = t.getChild (k);
      if (u.getLocalIndex () < u.getNet ()->myNumCallees &&
        u.getNet ()->myCallees[u.getLocalIndex ()] == &u)
      continue; // do not fuse callee transitions in the child net

      // copy the arcs to the global synchronisation transition
      if (!trans.fuse (u, printer, true))
      ok = false;
      else {
      class Transition& child = const_cast<class Transition&>(u);
      trans.addChild (child);
      child.changeParent (t, trans);
      if (!child.isUnifiable (Transition::uRemove, printer))
        ok = false;
      }
    }

    // see that the fused synchronisation transition is unifiable
    if (ok && !trans.isUnifiable (t.getNumParents ()
                          ? Transition::uIgnore
                          : Transition::uNormal,
                          printer))
      ok = false;
  }

  return ok;
}


Generated by  Doxygen 1.6.0   Back to index