FreeBSD/contrib/gcc/cp/name-lookup.c
/* Make the declaration(s) of X appear in CLASS scope under the name
   NAME.  Returns true if the binding is valid.  */
Make the declaration(s) of X appear in CLASS scope under the name
NAME.  Returns true if the binding is valid.
Make the declaration ( s ) of X appear in CLASS scope under the name NAME . Returns true if the binding is valid .
bool
push_class_level_binding (tree name, tree x)
{
  cxx_binding *binding;
  tree decl = x;
  bool ok;
  timevar_push (TV_NAME_LOOKUP);
  if (!class_binding_level)
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
  if (name == error_mark_node)
    POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
  gcc_assert (TYPE_BEING_DEFINED (current_class_type));
  if (TREE_CODE (decl) == TREE_LIST
      && TREE_TYPE (decl) == error_mark_node)
    decl = TREE_VALUE (decl);
  check_template_shadow (decl);
  if ((TREE_CODE (x) == VAR_DECL
       || TREE_CODE (x) == CONST_DECL
       || (TREE_CODE (x) == TYPE_DECL
	   && !DECL_SELF_REFERENCE_P (x))
       || (TREE_CODE (x) == FIELD_DECL
	   && DECL_CONTEXT (x) != current_class_type))
      && DECL_NAME (x) == constructor_name (current_class_type))
    {
      tree scope = context_for_name_lookup (x);
      if (TYPE_P (scope) && same_type_p (scope, current_class_type))
	{
	  error ("%qD has the same name as the class in which it is "
		 "declared",
		 x);
	  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, false);
	}
    }
  binding = IDENTIFIER_BINDING (name);
  if (!binding || binding->scope != class_binding_level)
    {
      binding = get_class_binding (name, class_binding_level);
      if (binding)
	{
	  binding->previous = IDENTIFIER_BINDING (name);
	  IDENTIFIER_BINDING (name) = binding;
	}
    }
  if (binding && binding->value)
    {
      tree bval = binding->value;
      tree old_decl = NULL_TREE;
      if (INHERITED_VALUE_BINDING_P (binding))
	{
	  if (TREE_CODE (bval) == TYPE_DECL && DECL_ARTIFICIAL (bval)
	      && !(TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x)))
	    {
	      old_decl = binding->type;
	      binding->type = bval;
	      binding->value = NULL_TREE;
	      INHERITED_VALUE_BINDING_P (binding) = 0;
	    }
	  else
	    {
	      old_decl = bval;
	      if (TREE_CODE (x) == TYPE_DECL && DECL_ARTIFICIAL (x))
		binding->type = NULL_TREE;
	    }
	}
      else if (TREE_CODE (x) == OVERLOAD && is_overloaded_fn (bval))
	old_decl = bval;
      else if (TREE_CODE (x) == USING_DECL && TREE_CODE (bval) == USING_DECL)
	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
      else if (TREE_CODE (x) == USING_DECL && is_overloaded_fn (bval))
	old_decl = bval;
      else if (TREE_CODE (bval) == USING_DECL && is_overloaded_fn (x))
	POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
      if (old_decl && binding->scope == class_binding_level)
	{
	  binding->value = x;
	  INHERITED_VALUE_BINDING_P (binding) = 0;
	  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, true);
	}
    }
  note_name_declared_in_class (name, decl);
  if (binding && binding->scope == class_binding_level)
    ok = supplement_binding (binding, decl);
  else
    {
      push_binding (name, decl, class_binding_level);
      ok = true;
    }
  POP_TIMEVAR_AND_RETURN (TV_NAME_LOOKUP, ok);
}
bool push_class_level_binding ( tree name , tree x ) { cxx_binding * binding ; tree decl = x ; bool ok ; timevar_push ( TV_NAME_LOOKUP ) ; if ( ! class_binding_level ) POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , true ) ; if ( name == error_mark_node ) POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , false ) ; gcc_assert ( TYPE_BEING_DEFINED ( current_class_type ) ) ; if ( TREE_CODE ( decl ) == TREE_LIST && TREE_TYPE ( decl ) == error_mark_node ) decl = TREE_VALUE ( decl ) ; check_template_shadow ( decl ) ; if ( ( TREE_CODE ( x ) == VAR_DECL || TREE_CODE ( x ) == CONST_DECL || ( TREE_CODE ( x ) == TYPE_DECL && ! DECL_SELF_REFERENCE_P ( x ) ) || ( TREE_CODE ( x ) == FIELD_DECL && DECL_CONTEXT ( x ) != current_class_type ) ) && DECL_NAME ( x ) == constructor_name ( current_class_type ) ) { tree scope = context_for_name_lookup ( x ) ; if ( TYPE_P ( scope ) && same_type_p ( scope , current_class_type ) ) { error ( " " " " , x ) ; POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , false ) ; } } binding = IDENTIFIER_BINDING ( name ) ; if ( ! binding || binding -> scope != class_binding_level ) { binding = get_class_binding ( name , class_binding_level ) ; if ( binding ) { binding -> previous = IDENTIFIER_BINDING ( name ) ; IDENTIFIER_BINDING ( name ) = binding ; } } if ( binding && binding -> value ) { tree bval = binding -> value ; tree old_decl = NULL_TREE ; if ( INHERITED_VALUE_BINDING_P ( binding ) ) { if ( TREE_CODE ( bval ) == TYPE_DECL && DECL_ARTIFICIAL ( bval ) && ! ( TREE_CODE ( x ) == TYPE_DECL && DECL_ARTIFICIAL ( x ) ) ) { old_decl = binding -> type ; binding -> type = bval ; binding -> value = NULL_TREE ; INHERITED_VALUE_BINDING_P ( binding ) = 0 ; } else { old_decl = bval ; if ( TREE_CODE ( x ) == TYPE_DECL && DECL_ARTIFICIAL ( x ) ) binding -> type = NULL_TREE ; } } else if ( TREE_CODE ( x ) == OVERLOAD && is_overloaded_fn ( bval ) ) old_decl = bval ; else if ( TREE_CODE ( x ) == USING_DECL && TREE_CODE ( bval ) == USING_DECL ) POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , true ) ; else if ( TREE_CODE ( x ) == USING_DECL && is_overloaded_fn ( bval ) ) old_decl = bval ; else if ( TREE_CODE ( bval ) == USING_DECL && is_overloaded_fn ( x ) ) POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , true ) ; if ( old_decl && binding -> scope == class_binding_level ) { binding -> value = x ; INHERITED_VALUE_BINDING_P ( binding ) = 0 ; POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , true ) ; } } note_name_declared_in_class ( name , decl ) ; if ( binding && binding -> scope == class_binding_level ) ok = supplement_binding ( binding , decl ) ; else { push_binding ( name , decl , class_binding_level ) ; ok = true ; } POP_TIMEVAR_AND_RETURN ( TV_NAME_LOOKUP , ok ) ; }
Make the declaration(s) of X appear in CLASS scope under the name
NAME.
Make the declaration ( s ) of X appear in CLASS scope under the name NAME .
/* The class_binding_level will be NULL if x is a template
     parameter name in a member template.  */ /* Check for invalid member names.  */ /* We could have been passed a tree list if this is an ambiguous
     declaration. If so, pull the declaration out because
     check_template_shadow will not handle a TREE_LIST.  */ /* [class.mem]

     If T is the name of a class, then each of the following shall
     have a name different from T:

     -- every static data member of class T;

     -- every member of class T that is itself a type;

     -- every enumerator of every member of class T that is an
	enumerated type;

     -- every member of every anonymous union that is a member of
	class T.

     (Non-static data members were also forbidden to have the same
     name as T until TC1.)  */ /* A data member of an anonymous union.  */ /* Get the current binding for NAME in this class, if any.  */ /* If a new binding was created, put it at the front of the
	 IDENTIFIER_BINDING list.  */ /* If there is already a binding, then we may need to update the
     current value.  */ /* If the old binding was from a base class, and was for a
	     tag name, slide it over to make room for the new binding.
	     The old binding is still visible if explicitly qualified
	     with a class-key.  */ /* Any inherited type declaration is hidden by the type
		 declaration in the derived class.  */ /* It is always safe to clear INHERITED_VALUE_BINDING_P
	     here.  This function is only used to register bindings
	     from with the class definition itself.  */ /* Note that we declared this value so that we can issue an error if
     this is an invalid redeclaration of a name already used for some
     other purpose.  */ /* If we didn't replace an existing binding, put the binding on the
     stack of bindings for the identifier, and update the shadowed
     list.  */ /* Supplement the existing binding.  */ /* Create a new binding.  */