'Visitor method for AST traversal. Used as arg for AST nodes\' \'accept\'
method (Visitor Design Pattern)'

def _visitor(self, node):

    def locatescope():
        while True:
            currscope = self._scopes[(-1)]
            if ((node.__class__.__name__ == 'GlobalParentNodeType') or (currscope._ast_node == node._parent_node)):
                return currscope
            self._scopes.pop()
    nodety = type(node)
    stoponthis = False
    newobj = None
    if (nodety in (phpast.FunctionCall, phpast.Echo, phpast.Print, phpast.Include, phpast.Require)):
        name = getattr(node, 'name', node.__class__.__name__.lower())
        newobj = FuncCall(name, node.lineno, node, locatescope())
        self._functions.append(newobj)
        stoponthis = True
    elif (nodety is phpast.Assignment):
        currscope = locatescope()
        varnode = node.node
        newobj = VariableDef(varnode.name, varnode.lineno, currscope, ast_node=node.expr)
        currscope.add_var(newobj)
        stoponthis = True
    elif (nodety in (phpast.Block, phpast.If, phpast.Else, phpast.ElseIf, phpast.While, phpast.DoWhile, phpast.For, phpast.Foreach)):
        parentscope = locatescope()
        if (nodety in (phpast.Else, phpast.ElseIf)):
            parentscope = parentscope._parent_scope
        newscope = Scope(node, parent_scope=parentscope)
        self._scopes.append(newscope)
    if (self.debugmode and newobj):
        print newobj
    return stoponthis
