# Path: xtuml/meta.py
# def navigate_one(self, instance):
#     '''
#     Navigate from *instance* across the link.
#     '''
#     return next(iter(self.navigate(instance)), None)
# 
# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_many(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
#     
#     The resulting query will return a set of instances.
#     '''
#     return NavChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_subtype(supertype, rel_id):
#     '''
#     Perform a navigation from *supertype* to its subtype across *rel_id*. The
#     navigated association must be modeled as a subtype-supertype association.
#     
#     The return value will an instance or None.
#     '''
#     if not supertype:
#         return
#     
#     if isinstance(rel_id, int):
#         rel_id = 'R%d' % rel_id
# 
#     metaclass = get_metaclass(supertype)
#     for kind, rel_id_candidate, _ in metaclass.links:
#         if rel_id != rel_id_candidate:
#             continue
#         
#         subtype = navigate_one(supertype).nav(kind, rel_id)()
#         if subtype:
#             return subtype
# 
# Path: xtuml/tools.py
# class Walker(object):
#     '''
#     A walker may be used to walk a tree.
#     '''
#     def __init__(self):
#         #: A list of *visitors* to notify when visiting nodes.
#         self.visitors = list()
#         
#     def accept(self, node, **kwargs):
#         '''
#         Invoke the visitors before and after decending down the tree. 
#         The walker will also try to invoke a method matching the pattern 
#         *accept_<type name>*, where <type name> is the name of the accepted
#         *node*.
#         '''
#         if node is None:
#             return
#         
#         for v in self.visitors:
#             v.enter(node)
#         
#         name = 'accept_' + node.__class__.__name__
#         fn = getattr(self, name, self.default_accept)
#         r = fn(node, **kwargs)
#         
#         for v in self.visitors:
#             v.leave(node)
#         
#         return r
#     
#     def default_accept(self, node, **kwargs):
#         '''
#         The default accept behaviour is to decend into the iterable member
#         *node.children* (if available).
#         '''
#         if not hasattr(node, 'children'):
#             return
#         
#         for child in node.children:
#             self.accept(child, **kwargs)


import logging
from xtuml import navigate_one as one
from xtuml import navigate_any as any
from xtuml import navigate_many as many
from xtuml import navigate_subtype as subtype
from xtuml.tools import Walker
        self.buf('->', o_obj.Key_Lett, '[R', str(r_rel.Numb))
        if inst.Rel_Phrase:
            self.buf('.', inst.Rel_Phrase)
        self.buf(']')
        self.accept(one(inst).ACT_LNK[604, 'precedes']())
        
    def accept_ACT_AI(self, inst):
        if one(inst).V_VAL[609].V_MSV[801]():
            self.buf('send ')
        else:
            self.buf('assign ')
            
        self.accept(one(inst).V_VAL[689]())
        self.buf(' = ')
        self.accept(one(inst).V_VAL[609]())

    def accept_ACT_WHL(self, inst):
        self.buf('while ')
        self.accept(one(inst).V_VAL[626]())
        self.accept(one(inst).ACT_BLK[608]())
        self.buf('end while')
        
    def accept_ACT_IF(self, inst):
        by_position = lambda inst: (one(inst).ACT_SMT[603]().LineNumber,
                                    one(inst).ACT_SMT[603]().StartPosition)
        
        self.buf('if ')
        self.accept(one(inst).V_VAL[625]())
        self.accept(one(inst).ACT_BLK[607]())
        

# Path: xtuml/meta.py
# def navigate_one(self, instance):
#     '''
#     Navigate from *instance* across the link.
#     '''
#     return next(iter(self.navigate(instance)), None)
# 
# Path: xtuml/meta.py
# def navigate_any(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
# 
#     The resulting query will return an instance or None.
#     '''
#     return NavOneChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_many(instance_or_set):
#     '''
#     Initialize a navigation from an instance, or a set of instances, to 
#     associated instances across a one-to-many or many-to-many association.
#     
#     The resulting query will return a set of instances.
#     '''
#     return NavChain(instance_or_set)
# 
# Path: xtuml/meta.py
# def navigate_subtype(supertype, rel_id):
#     '''
#     Perform a navigation from *supertype* to its subtype across *rel_id*. The
#     navigated association must be modeled as a subtype-supertype association.
#     
#     The return value will an instance or None.
#     '''
#     if not supertype:
#         return
#     
#     if isinstance(rel_id, int):
#         rel_id = 'R%d' % rel_id
# 
#     metaclass = get_metaclass(supertype)
#     for kind, rel_id_candidate, _ in metaclass.links:
#         if rel_id != rel_id_candidate:
#             continue
#         
#         subtype = navigate_one(supertype).nav(kind, rel_id)()
#         if subtype:
#             return subtype
# 
# Path: xtuml/tools.py
# class Walker(object):
#     '''
#     A walker may be used to walk a tree.
#     '''
#     def __init__(self):
#         #: A list of *visitors* to notify when visiting nodes.
#         self.visitors = list()
#         
#     def accept(self, node, **kwargs):
#         '''
#         Invoke the visitors before and after decending down the tree. 
#         The walker will also try to invoke a method matching the pattern 
#         *accept_<type name>*, where <type name> is the name of the accepted
#         *node*.
#         '''
#         if node is None:
#             return
#         
#         for v in self.visitors:
#             v.enter(node)
#         
#         name = 'accept_' + node.__class__.__name__
#         fn = getattr(self, name, self.default_accept)
#         r = fn(node, **kwargs)
#         
#         for v in self.visitors:
#             v.leave(node)
#         
#         return r
#     
#     def default_accept(self, node, **kwargs):
#         '''
#         The default accept behaviour is to decend into the iterable member
#         *node.children* (if available).
#         '''
#         if not hasattr(node, 'children'):
#             return
#         
#         for child in node.children:
#             self.accept(child, **kwargs)


# Path: bridgepoint/sourcegen.py
import logging
from xtuml import navigate_one as one
from xtuml import navigate_any as any
from xtuml import navigate_many as many
from xtuml import navigate_subtype as subtype
from xtuml.tools import Walker

        self.buf('->', o_obj.Key_Lett, '[R', str(r_rel.Numb))
        if inst.Rel_Phrase:
            self.buf('.', inst.Rel_Phrase)
        self.buf(']')
        self.accept(one(inst).ACT_LNK[604, 'precedes']())
        
    def accept_ACT_AI(self, inst):
        if one(inst).V_VAL[609].V_MSV[801]():
            self.buf('send ')
        else:
            self.buf('assign ')
            
        self.accept(one(inst).V_VAL[689]())
        self.buf(' = ')
        self.accept(one(inst).V_VAL[609]())

    def accept_ACT_WHL(self, inst):
        self.buf('while ')
        self.accept(one(inst).V_VAL[626]())
        self.accept(one(inst).ACT_BLK[608]())
        self.buf('end while')
        
    def accept_ACT_IF(self, inst):
        by_position = lambda inst: (one(inst).ACT_SMT[603]().LineNumber,
                                    one(inst).ACT_SMT[603]().StartPosition)
        
        self.buf('if ')
        self.accept(one(inst).V_VAL[625]())
        self.accept(one(inst).ACT_BLK[607]())
        

        for act_el in sorted(many(inst).ACT_EL[682](), key=by_position):