code: def __findout_range(self, name, decl_type, recursive):
          
          if not self._optimized:
              self._logger.debug(
                  'running non optimized query - optimization has not been done')
              decls = self.declarations
              if recursive:
                  decls = make_flatten(self.declarations)
              if decl_type:
                  decls = [d for d in decls if isinstance(d, decl_type)]
              return decls
  
          if name and templates.is_instantiation(name):
              # templates has tricky mode to compare them, so lets check the
              # whole range
              name = None
  
          if name and decl_type:
              impl_match = scopedef_t._impl_matchers[scopedef_t.decl](name=name)
              if impl_match.is_full_name():
                  name = impl_match.decl_name_only
              if recursive:
                  self._logger.debug(
                      'query has been optimized on type and name')
                  return self._type2name2decls[decl_type].get(name, [])
  
              self._logger.debug(
                  'non recursive query has been optimized on type and name')
              return self._type2name2decls_nr[decl_type].get(name, [])
          elif decl_type:
              if recursive:
                  self._logger.debug('query has been optimized on type')
                  return self._type2decls[decl_type]
  
              self._logger.debug(
                  'non recursive query has been optimized on type')
              return self._type2decls_nr[decl_type]
          else:
              if recursive:
                  self._logger.debug((
                      'query has not been optimized ( hint: query does not ' +
                      'contain type and/or name )'))
                  return self._all_decls
  
              self._logger.debug((
                  'non recursive query has not been optimized ( hint: ' +
                  'query does not contain type and/or name )'))
              return self._all_decls_not_recursive
docs: implementation details