Skip to content

Instantly share code, notes, and snippets.

@jbeard4
Created March 3, 2011 22:23
Show Gist options
  • Save jbeard4/853745 to your computer and use it in GitHub Desktop.
Save jbeard4/853745 to your computer and use it in GitHub Desktop.
enterStates and addStatesToEnter specification
procedure enterStates(enabledTransitions):
statesToEnter = new OrderedSet()
statesForDefaultEntry = new OrderedSet()
for t in enabledTransitions:
if t.target:
LCA = findLCA([t.source].append(getTargetStates(t.target)))
addStatesToEnter(getTargetStates(t.target),LCA,statesToEnter,statesForDefaultEntry)
if isParallelState(LCA):
for child in getChildStates(LCA):
addStatesToEnter(child,LCA,statesToEnter,statesForDefaultEntry)
for s in statesToEnter:
statesToInvoke.add(s)
statesToEnter = statesToEnter.toList().sort(enterOrder)
for s in statesToEnter:
configuration.add(s)
for content in s.onentry:
executeContent(content)
if statesForDefaultEntry.member(s):
executeContent(s.initial.transition)
if isFinalState(s):
parent = s.parent
grandparent = parent.parent
internalQueue.enqueue(new Event("done.state." + parent.id, parent.donedata))
if isParallelState(grandparent):
if getChildStates(grandparent).every(isInFinalState):
internalQueue.enqueue(new Event("done.state." + grandparent.id, grandparent.donedata))
for s in configuration:
if isFinalState(s) and isScxmlState(s.parent):
continue = false
procedure recursiveAddStatesToEnter(s,root,statesToEnter,statesForDefaultEntry):
if isHistoryState(s):
if historyValue[s.id]:
for s0 in historyValue[s.id]:
addStatesToEnter(s0,s,statesToEnter,statesForDefaultEntry)
else:
for t in s.transition:
for s0 in getTargetStates(t.target):
addStatesToEnter(s0,s,statesToEnter,statesForDefaultEntry)
else:
statesToEnter.add(s)
if isParallelState(s):
for child in getChildStates(s):
addStatesToEnter(child,s,statesToEnter,statesForDefaultEntry)
elif isCompoundState(s):
statesForDefaultEntry.add(s)
for tState in getTargetStates(s.initial):
addStatesToEnter(tState, s, statesToEnter, statesForDefaultEntry)
for anc in getProperAncestors(s,root):
statesToEnter.add(anc)
if isParallelState(anc):
for pChild in getChildStates(anc):
if not statesToEnter.toList().some(lambda s2: isDescendant(s2,pChild)):
addStatesToEnter(pChild,anc,statesToEnter,statesForDefaultEntry)
procedure addStatesToEnter(statesToRecursivelyAdd,root,statesToEnter,statesForDefaultEntry):
do:
for s in statesToRecursivelyAdd
recursiveAddStatesToEnter(s,root,statesToEnter,statesForDefaultEntry);
while ((statesToRecursivelyAdd =
getChildrenOfParallelStatesWithoutDescendantsInStatesToEnter(statesToEnter)) &&
statesToRecursivelyAdd.length);
function getChildrenOfParallelStatesWithoutDescendantsInStatesToEnter(statesToEnter){
return statesToEnter
.toList()
.filter(isParallelState)
.map(getChildStates)
.reduce(function(a,b){return a.concat(b)},[])
.filter(function(pChild){
return !statesToEnter.toList().some(
function(s2){return isDescendant(s2,pChild)})});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment