<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def apply_visitor(visitor, decl_inst):
 """ Applies a visitor on declaration instance. :param visitor: instance :type visitor: :class:`type_visitor_t` or :class:`decl_visitor_t` """


    fname = 'visit_' + \
        decl_inst.__class__.__name__[:-2]  # removing '_t' from class name
    if not hasattr(visitor, fname):
        raise runtime_errors.visit_function_has_not_been_found_t(
            visitor, decl_inst)
    return getattr(visitor, fname)()