This is a detailed look at the details of deleting Concepts in Chasm. If you want an overview, see here.
It all starts with deleteCO(CO*) : void. This is actually a preprocessor define however for CO::deleteCO_i(CO*, LINE,FILE,func): void. This a few things. First, it checks that you are not deleting something already deleted or never allocated. Then, it sees if you are deleting something initialized. If not, then it just deletes it. If you are, then it sends it the end symbol to start the delete process. It then returns.
The end symbol eventually is sent to the Q::processEvent(Event*) method. Since it is the end symbol, it checks if the Concept is needed by other concepts using the CO::isNeeded method or, for PCO's, the PCO::isNeeded method.
CO::isNeeded
This calls CO::isObserved to see if any state in this concept is being observed, entry or exit. If any are, then it returns true, else false.
PCO::isNeeded
This checks to see if any instances of this exist or if it is a child for any other PCO. If any exist, then return true, else false.
If it is needed, then call needingConceptNotifyWhenDeleted.
CO::needingConceptNotifyWhenDeleted
This looks through its states for an observer, entry or exit. When it finds one, it tells that Concept to notify this when it deletes through CO::addNotifyOnDelete(this). Lastly, it sets the bool variable as true for waitingtodelete. It errors if it does not find an observer.
PCO::needingConceptNotifyWhenDeleted
This looks through the instances of this taking the 1st. If it is an imposter concept, then use its PCO. If no instances, use the 1st child. Take either the 1st instance, the 1st instance's imposter's PCO or the 1st child and call CO::addNotifyOnDelete(this). Lastly, it sets the bool variable as true for waitingtodelete. It errors if it does not find an observer.
NOTE: CO::addNotifyOnDelete just appends the concept to the notifyondelete list.
If it is not needed, handle the end symbols just as any other.
When handling the end symbol, it should transition into the end state causing this state entry function to be called. If not, there are problems...
Lastly, this returns the del symbol. Notice how the deleteCOs for the components are called first so they will be dealt with before the del symbol.
Like the end symbol, the del symbol goes through the Q::processEvent method and is filtered out to be handled separately from the other symbols. The first thing it does it check to see if there are concepts in the notifyondeletelist.
if notifiers
Create a new cascade, placing this del symbol onto the bottom of the new cascade in the continuation stack. Then, place each notifier on the same stack with their end symbol.
If no notifiers
Then if not waitingfornotifiersdelete or if the event is coming from the same CO which is deleting, then delete the concept. Else, just wait for the event to come around.
There should not be any instances at this point and errors if there are. After checking this, it uninherites from its parent class if it has a parent class. Then it removes itself from the master list of PCOs and finally frees the memory used to store the directory information.
A whole slew of stuff happens here.