FreeBSD/contrib/gcc/cp/name-lookup.c
/* Look up NAME in the current binding level and its superiors in the
   namespace of variables, functions and typedefs.  Return a ..._DECL
   node of some kind representing its definition if there is only one
   such declaration, or return a TREE_LIST with all the overloaded
   definitions if there are many, or return 0 if it is undefined.
   Hidden name, either friend declaration or built-in function, are
   not ignored.

   If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces.
   If PREFER_TYPE is > 1, we reject non-type decls (e.g. namespaces).
   Otherwise we prefer non-TYPE_DECLs.

   If NONCLASS is nonzero, bindings in class scopes are ignored.  If
   BLOCK_P is false, bindings in block scopes are ignored.  */
Look up NAME in the current binding level and its superiors in the
namespace of variables, functions and typedefs.  Return a ..._DECL
node of some kind representing its definition if there is only one
such declaration, or return a TREE_LIST with all the overloaded
definitions if there are many, or return 0 if it is undefined.
Hidden name, either friend declaration or built-in function, are
not ignored.

If PREFER_TYPE is > 0, we prefer TYPE_DECLs or namespaces.
If PREFER_TYPE is > 1, we reject non-type decls .
Otherwise we prefer non-TYPE_DECLs.

If NONCLASS is nonzero, bindings in class scopes are ignored.  If
BLOCK_P is false, bindings in block scopes are ignored.
Look up NAME in the current binding level and its superiors in the namespace of variables functions and typedefs . Return a ... _DECL node of some kind representing its definition if there is only one such declaration or return a TREE_LIST with all the overloaded definitions if there are many or return 0 if it is undefined . Hidden name either friend declaration or built - in function are not ignored . If PREFER_TYPE is > 0 we prefer TYPE_DECLs or namespaces . If PREFER_TYPE is > 1 we reject non - type decls . Otherwise we prefer non - TYPE_DECLs . If NONCLASS is nonzero bindings in class scopes are ignored . If BLOCK_P is false bindings in block scopes are ignored .
tree
lookup_name_real (tree name, int prefer_type, int nonclass, bool block_p,
		  int namespaces_only, int flags)
{
  cxx_binding *iter;
  tree val = NULL_TREE;
  timevar_push (TV_NAME_LOOKUP);
  if (IDENTIFIER_TYPENAME_P (name))
    {
      struct cp_binding_level *level;
      for (level = current_binding_level;
	   level && level->kind != sk_namespace;
	   level = level->level_chain)
	{
	  tree class_type;
	  tree operators;
	  if (level->kind != sk_class)
	    continue;
	  class_type = level->this_entity;
	  operators = lookup_fnfields (class_type, name, 0);
	  if (operators)
	    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, operators);
	}
      POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
    }
  flags |= lookup_flags (prefer_type, namespaces_only);
  if (current_class_type == NULL_TREE)
    nonclass = 1;
  if (block_p || !nonclass)
    for (iter = outer_binding (name, NULL, !nonclass);
	 iter;
	 iter = outer_binding (name, iter, !nonclass))
      {
	tree binding;
	if (LOCAL_BINDING_P (iter) ? !block_p : nonclass)
	  continue;
	if (qualify_lookup (iter->value, flags))
	  binding = iter->value;
	else if ((flags & LOOKUP_PREFER_TYPES)
		 && qualify_lookup (iter->type, flags))
	  binding = iter->type;
	else
	  binding = NULL_TREE;
	if (binding)
	  {
	    if (hidden_name_p (binding))
	      {
		gcc_assert (current_class_type &&
			    LOCAL_CLASS_P (current_class_type));
		POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, NULL_TREE);
	      }
	    val = binding;
	    break;
	  }
      }
  if (!val)
    val = unqualified_namespace_lookup (name, flags);
  if (val && TREE_CODE (val) == OVERLOAD && !really_overloaded_fn (val))
    val = OVL_FUNCTION (val);
  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, val);
}
tree lookup_name_real ( tree name , int prefer_type , int nonclass , bool block_p , int namespaces_only , int flags ) { cxx_binding * iter ; tree val = NULL_TREE ; timevar_push ( TV_NAME_LOOKUP ) ; if ( IDENTIFIER_TYPENAME_P ( name ) ) { struct cp_binding_level * level ; for ( level = current_binding_level ; level && level -> kind != sk_namespace ; level = level -> level_chain ) { tree class_type ; tree operators ; if ( level -> kind != sk_class ) continue ; class_type = level -> this_entity ; operators = lookup_fnfields ( class_type , name , 0 ) ; if ( operators ) POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , operators ) ; } POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , NULL_TREE ) ; } flags |= lookup_flags ( prefer_type , namespaces_only ) ; if ( current_class_type == NULL_TREE ) nonclass = 1 ; if ( block_p || ! nonclass ) for ( iter = outer_binding ( name , NULL , ! nonclass ) ; iter ; iter = outer_binding ( name , iter , ! nonclass ) ) { tree binding ; if ( LOCAL_BINDING_P ( iter ) ? ! block_p : nonclass ) continue ; if ( qualify_lookup ( iter -> value , flags ) ) binding = iter -> value ; else if ( ( flags & LOOKUP_PREFER_TYPES ) && qualify_lookup ( iter -> type , flags ) ) binding = iter -> type ; else binding = NULL_TREE ; if ( binding ) { if ( hidden_name_p ( binding ) ) { gcc_assert ( current_class_type && LOCAL_CLASS_P ( current_class_type ) ) ; POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , NULL_TREE ) ; } val = binding ; break ; } } if ( ! val ) val = unqualified_namespace_lookup ( name , flags ) ; if ( val && TREE_CODE ( val ) == OVERLOAD && ! really_overloaded_fn ( val ) ) val = OVL_FUNCTION ( val ) ; POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , val ) ; }
Look up NAME in the current binding level and its superiors in the
namespace of variables, functions and typedefs.
Look up NAME in the current binding level and its superiors in the namespace of variables functions and typedefs .
/* Conversion operators are handled specially because ordinary
     unqualified name lookup will not find template conversion
     operators.  */ /* A conversion operator can only be declared in a class
	     scope.  */ /* Lookup the conversion operator in the class.  */ /*protect=*/ /* First, look in non-namespace scopes.  */ /* Skip entities we don't want.  */ /* If this is the kind of thing we're looking for, we're done.  */ /* A non namespace-scope binding can only be hidden if
		   we are in a local class, due to friend declarations.
		   In particular, consider:

		   void f() {
		     struct A {
		       friend struct B;
		       void g() { B* b; } // error: B is hidden
		     }
		     struct B {};
		   }

		   The standard says that "B" is a local class in "f"
		   (but not nested within "A") -- but that name lookup
		   for "B" does not find this declaration until it is
		   declared directly with "f".

		   In particular:

		   [class.friend]

		   If a friend declaration appears in a local class and
		   the name specified is an unqualified name, a prior
		   declaration is looked up without considering scopes
		   that are outside the innermost enclosing non-class
		   scope. For a friend class declaration, if there is no
		   prior declaration, the class that is specified 
		   belongs to the innermost enclosing non-class scope,
		   but if it is subsequently referenced, its name is not
		   found by name lookup until a matching declaration is
		   provided in the innermost enclosing nonclass scope.
		*/ /* This binding comes from a friend declaration in the local
		   class. The standard (11.4.8) states that the lookup can
		   only succeed if there is a non-hidden declaration in the
		   current scope, which is not the case here.  */ /* Now lookup in namespace scopes.  */ /* If we have a single function from a using decl, pull it out.  */