![]() |
![]() |
Public Member Functions | |
def | __init__ |
def | enter |
def | leave |
def | result |
Private Member Functions | |
def | _didApply |
Private Attributes | |
__didApply | |
__operator | |
__result | |
__stack |
Traverses a Sequence and constructs a new sequence by applying the operator to each element of the sequence
Definition at line 601 of file SequenceTypes.py.
def SequenceTypes::_MutatingSequenceVisitor::__init__ | ( | self, | |
operator | |||
) |
Reimplemented in SequenceTypes::_CopyAndRemoveFirstSequenceVisitor, and SequenceTypes::_CopyAndExcludeSequenceVisitor.
Definition at line 603 of file SequenceTypes.py.
def SequenceTypes::_MutatingSequenceVisitor::_didApply | ( | self | ) | [private] |
Definition at line 682 of file SequenceTypes.py.
def SequenceTypes::_MutatingSequenceVisitor::enter | ( | self, | |
visitee | |||
) |
Definition at line 609 of file SequenceTypes.py.
00610 : 00611 if len(self.__stack) > 0: 00612 #add visitee to its parent's stack entry 00613 self.__stack[-1].append([visitee,False]) 00614 v = self.__operator(visitee) 00615 if v is not visitee: 00616 #was changed 00617 self.__didApply = True 00618 self.__stack[-1][-1]=[v,True] 00619 if not isinstance(visitee, _SequenceLeaf): 00620 #need to add a stack entry to keep track of children self.__stack.append(list())
def SequenceTypes::_MutatingSequenceVisitor::leave | ( | self, | |
visitee | |||
) |
Definition at line 621 of file SequenceTypes.py.
00622 : 00623 node = visitee 00624 if not isinstance(visitee,_SequenceLeaf): 00625 #were any children changed? 00626 l = self.__stack[-1] 00627 changed = False 00628 countNulls = 0 00629 nonNulls = list() 00630 for c in l: 00631 if c[1] == True: 00632 changed = True 00633 if c[0] is None: 00634 countNulls +=1 00635 else: 00636 nonNulls.append(c[0]) 00637 if changed: 00638 if countNulls != 0: 00639 #this node must go away 00640 if len(nonNulls) == 0: 00641 #all subnodes went away 00642 node = None 00643 else: 00644 node = nonNulls[0] 00645 for n in nonNulls[1:]: 00646 node = node+n 00647 else: 00648 #some child was changed so we need to clone 00649 # this node and replace it with one that holds 00650 # the new child(ren) 00651 children = [x[0] for x in l ] 00652 if not isinstance(visitee,Sequence): 00653 node = visitee.__new__(type(visitee)) 00654 node.__init__(*children) 00655 else: 00656 node = nonNulls[0] 00657 for n in nonNulls[1:]: 00658 node = node+n 00659 00660 if node != visitee: 00661 #we had to replace this node so now we need to 00662 # change parent's stack entry as well 00663 if len(self.__stack) > 1: 00664 p = self.__stack[-2] 00665 #find visitee and replace 00666 for i,c in enumerate(p): 00667 if c[0]==visitee: 00668 c[0]=node 00669 c[1]=True 00670 break 00671 if not isinstance(visitee,_SequenceLeaf): self.__stack = self.__stack[:-1]
def SequenceTypes::_MutatingSequenceVisitor::result | ( | self | ) |
Definition at line 672 of file SequenceTypes.py.
Definition at line 603 of file SequenceTypes.py.
Definition at line 603 of file SequenceTypes.py.
Definition at line 603 of file SequenceTypes.py.
Definition at line 603 of file SequenceTypes.py.