FreeBSD/contrib/gcc/cp/parser.c
/* Looks up NAME in the current scope, as given by PARSER->SCOPE.
   NAME should have one of the representations used for an
   id-expression.  If NAME is the ERROR_MARK_NODE, the ERROR_MARK_NODE
   is returned.  If PARSER->SCOPE is a dependent type, then a
   SCOPE_REF is returned.

   If NAME is a TEMPLATE_ID_EXPR, then it will be immediately
   returned; the name was already resolved when the TEMPLATE_ID_EXPR
   was formed.  Abstractly, such entities should not be passed to this
   function, because they do not need to be looked up, but it is
   simpler to check for this special case here, rather than at the
   call-sites.

   In cases not explicitly covered above, this function returns a
   DECL, OVERLOAD, or baselink representing the result of the lookup.
   If there was no entity with the indicated NAME, the ERROR_MARK_NODE
   is returned.

   If TAG_TYPE is not NONE_TYPE, it indicates an explicit type keyword
   (e.g., "struct") that was used.  In that case bindings that do not
   refer to types are ignored.

   If IS_TEMPLATE is TRUE, bindings that do not refer to templates are
   ignored.

   If IS_NAMESPACE is TRUE, bindings that do not refer to namespaces
   are ignored.

   If CHECK_DEPENDENCY is TRUE, names are not looked up in dependent
   types.

   If AMBIGUOUS_DECLS is non-NULL, *AMBIGUOUS_DECLS is set to a
   TREE_LIST of candidates if name-lookup results in an ambiguity, and
   NULL_TREE otherwise.  */
Looks up NAME in the current scope, as given by PARSER->SCOPE.
NAME should have one of the representations used for an
id-expression.  If NAME is the ERROR_MARK_NODE, the ERROR_MARK_NODE
is returned.  If PARSER->SCOPE is a dependent type, then a
SCOPE_REF is returned.

If NAME is a TEMPLATE_ID_EXPR, then it will be immediately
returned; the name was already resolved when the TEMPLATE_ID_EXPR
was formed.  Abstractly, such entities should not be passed to this
function, because they do not need to be looked up, but it is
simpler to check for this special case here, rather than at the
call-sites.

In cases not explicitly covered above, this function returns a
DECL, OVERLOAD, or baselink representing the result of the lookup.
If there was no entity with the indicated NAME, the ERROR_MARK_NODE
is returned.

If TAG_TYPE is not NONE_TYPE, it indicates an explicit type keyword
that was used.  In that case bindings that do not
refer to types are ignored.

If IS_TEMPLATE is TRUE, bindings that do not refer to templates are
ignored.

If IS_NAMESPACE is TRUE, bindings that do not refer to namespaces
are ignored.

If CHECK_DEPENDENCY is TRUE, names are not looked up in dependent
types.

If AMBIGUOUS_DECLS is non-NULL, *AMBIGUOUS_DECLS is set to a
TREE_LIST of candidates if name-lookup results in an ambiguity, and
NULL_TREE otherwise.
Looks up NAME in the current scope as given by PARSER - > SCOPE . NAME should have one of the representations used for an id - expression . If NAME is the ERROR_MARK_NODE the ERROR_MARK_NODE is returned . If PARSER - > SCOPE is a dependent type then a SCOPE_REF is returned . If NAME is a TEMPLATE_ID_EXPR then it will be immediately returned ; the name was already resolved when the TEMPLATE_ID_EXPR was formed . Abstractly such entities should not be passed to this function because they do not need to be looked up but it is simpler to check for this special case here rather than at the call - sites . In cases not explicitly covered above this function returns a DECL OVERLOAD or baselink representing the result of the lookup . If there was no entity with the indicated NAME the ERROR_MARK_NODE is returned . If TAG_TYPE is not NONE_TYPE it indicates an explicit type keyword that was used . In that case bindings that do not refer to types are ignored . If IS_TEMPLATE is TRUE bindings that do not refer to templates are ignored . If IS_NAMESPACE is TRUE bindings that do not refer to namespaces are ignored . If CHECK_DEPENDENCY is TRUE names are not looked up in dependent types . If AMBIGUOUS_DECLS is non - NULL * AMBIGUOUS_DECLS is set to a TREE_LIST of candidates if name - lookup results in an ambiguity and NULL_TREE otherwise .
static tree
cp_parser_lookup_name (cp_parser *parser, tree name,
		       enum tag_types tag_type,
		       bool is_template,
		       bool is_namespace,
		       bool check_dependency,
		       tree *ambiguous_decls)
{
  int flags = 0;
  tree decl;
  tree object_type = parser->context->object_type;
  if (!cp_parser_uncommitted_to_tentative_parse_p (parser))
    flags |= LOOKUP_COMPLAIN;
  if (ambiguous_decls)
    *ambiguous_decls = NULL_TREE;
  parser->context->object_type = NULL_TREE;
  if (name == error_mark_node)
    return error_mark_node;
  if (TREE_CODE (name) == TEMPLATE_ID_EXPR)
    return name;
  if (BASELINK_P (name))
    {
      gcc_assert (TREE_CODE (BASELINK_FUNCTIONS (name))
		  == TEMPLATE_ID_EXPR);
      return name;
    }
  if (TREE_CODE (name) == BIT_NOT_EXPR)
    {
      tree type;
      if (parser->scope)
	type = parser->scope;
      else if (object_type)
	type = object_type;
      else
	type = current_class_type;
      if (!type || !CLASS_TYPE_P (type))
	return error_mark_node;
      if (CLASSTYPE_LAZY_DESTRUCTOR (type))
	lazily_declare_fn (sfk_destructor, type);
      if (!CLASSTYPE_DESTRUCTORS (type))
	  return error_mark_node;
      return CLASSTYPE_DESTRUCTORS (type);
    }
  gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
  if (parser->scope)
    {
      bool dependent_p;
      if (parser->scope == error_mark_node)
	return error_mark_node;
      dependent_p = (TYPE_P (parser->scope)
		     && !(parser->in_declarator_p
			  && currently_open_class (parser->scope))
		     && dependent_type_p (parser->scope));
      if ((check_dependency || !CLASS_TYPE_P (parser->scope))
	   && dependent_p)
	{
	  if (tag_type)
	    {
	      tree type;
	      type = make_typename_type (parser->scope, name, tag_type,
					 tf_error);
	      decl = TYPE_NAME (type);
	    }
	  else if (is_template
		   && (cp_parser_next_token_ends_template_argument_p (parser)
		       || cp_lexer_next_token_is (parser->lexer,
						  CPP_CLOSE_PAREN)))
	    decl = make_unbound_class_template (parser->scope,
						name, NULL_TREE,
						tf_error);
	  else
	    decl = build_qualified_name (NULL_TREE,
					 parser->scope, name,
					 is_template);
	}
      else
	{
	  tree pushed_scope = NULL_TREE;
	  if (dependent_p)
	    pushed_scope = push_scope (parser->scope);
	  decl = lookup_qualified_name (parser->scope, name,
					tag_type != none_type,
					true);
	  if (pushed_scope)
	    pop_scope (pushed_scope);
	}
      parser->qualifying_scope = parser->scope;
      parser->object_scope = NULL_TREE;
    }
  else if (object_type)
    {
      tree object_decl = NULL_TREE;
      if (CLASS_TYPE_P (object_type))
	object_decl = lookup_member (object_type,
				     name,
				     0,
				     tag_type != none_type);
      decl = lookup_name_real (name, tag_type != none_type,
			       0,
			       true, is_namespace, flags);
      parser->object_scope = object_type;
      parser->qualifying_scope = NULL_TREE;
      if (object_decl)
	decl = object_decl;
    }
  else
    {
      decl = lookup_name_real (name, tag_type != none_type,
			       0,
			       true, is_namespace, flags);
      parser->qualifying_scope = NULL_TREE;
      parser->object_scope = NULL_TREE;
    }
  if (!decl || decl == error_mark_node)
    return error_mark_node;
  if (TREE_CODE (decl) == TREE_LIST)
    {
      if (ambiguous_decls)
	*ambiguous_decls = decl;
      if (!cp_parser_simulate_error (parser))
	{
	  error ("reference to %qD is ambiguous", name);
	  print_candidates (decl);
	}
      return error_mark_node;
    }
  gcc_assert (DECL_P (decl)
	      || TREE_CODE (decl) == OVERLOAD
	      || TREE_CODE (decl) == SCOPE_REF
	      || TREE_CODE (decl) == UNBOUND_CLASS_TEMPLATE
	      || BASELINK_P (decl));
  if (DECL_P (decl))
    check_accessibility_of_qualified_id (decl, object_type, parser->scope);
  return decl;
}
static tree cp_parser_lookup_name ( cp_parser * parser , tree name , enum tag_types tag_type , bool is_template , bool is_namespace , bool check_dependency , tree * ambiguous_decls ) { int flags = 0 ; tree decl ; tree object_type = parser -> context -> object_type ; if ( ! cp_parser_uncommitted_to_tentative_parse_p ( parser ) ) flags |= LOOKUP_COMPLAIN ; if ( ambiguous_decls ) * ambiguous_decls = NULL_TREE ; parser -> context -> object_type = NULL_TREE ; if ( name == error_mark_node ) return error_mark_node ; if ( TREE_CODE ( name ) == TEMPLATE_ID_EXPR ) return name ; if ( BASELINK_P ( name ) ) { gcc_assert ( TREE_CODE ( BASELINK_FUNCTIONS ( name ) ) == TEMPLATE_ID_EXPR ) ; return name ; } if ( TREE_CODE ( name ) == BIT_NOT_EXPR ) { tree type ; if ( parser -> scope ) type = parser -> scope ; else if ( object_type ) type = object_type ; else type = current_class_type ; if ( ! type || ! CLASS_TYPE_P ( type ) ) return error_mark_node ; if ( CLASSTYPE_LAZY_DESTRUCTOR ( type ) ) lazily_declare_fn ( sfk_destructor , type ) ; if ( ! CLASSTYPE_DESTRUCTORS ( type ) ) return error_mark_node ; return CLASSTYPE_DESTRUCTORS ( type ) ; } gcc_assert ( TREE_CODE ( name ) == IDENTIFIER_NODE ) ; if ( parser -> scope ) { bool dependent_p ; if ( parser -> scope == error_mark_node ) return error_mark_node ; dependent_p = ( TYPE_P ( parser -> scope ) && ! ( parser -> in_declarator_p && currently_open_class ( parser -> scope ) ) && dependent_type_p ( parser -> scope ) ) ; if ( ( check_dependency || ! CLASS_TYPE_P ( parser -> scope ) ) && dependent_p ) { if ( tag_type ) { tree type ; type = make_typename_type ( parser -> scope , name , tag_type , tf_error ) ; decl = TYPE_NAME ( type ) ; } else if ( is_template && ( cp_parser_next_token_ends_template_argument_p ( parser ) || cp_lexer_next_token_is ( parser -> lexer , CPP_CLOSE_PAREN ) ) ) decl = make_unbound_class_template ( parser -> scope , name , NULL_TREE , tf_error ) ; else decl = build_qualified_name ( NULL_TREE , parser -> scope , name , is_template ) ; } else { tree pushed_scope = NULL_TREE ; if ( dependent_p ) pushed_scope = push_scope ( parser -> scope ) ; decl = lookup_qualified_name ( parser -> scope , name , tag_type != none_type , true ) ; if ( pushed_scope ) pop_scope ( pushed_scope ) ; } parser -> qualifying_scope = parser -> scope ; parser -> object_scope = NULL_TREE ; } else if ( object_type ) { tree object_decl = NULL_TREE ; if ( CLASS_TYPE_P ( object_type ) ) object_decl = lookup_member ( object_type , name , 0 , tag_type != none_type ) ; decl = lookup_name_real ( name , tag_type != none_type , 0 , true , is_namespace , flags ) ; parser -> object_scope = object_type ; parser -> qualifying_scope = NULL_TREE ; if ( object_decl ) decl = object_decl ; } else { decl = lookup_name_real ( name , tag_type != none_type , 0 , true , is_namespace , flags ) ; parser -> qualifying_scope = NULL_TREE ; parser -> object_scope = NULL_TREE ; } if ( ! decl || decl == error_mark_node ) return error_mark_node ; if ( TREE_CODE ( decl ) == TREE_LIST ) { if ( ambiguous_decls ) * ambiguous_decls = decl ; if ( ! cp_parser_simulate_error ( parser ) ) { error ( " " , name ) ; print_candidates ( decl ) ; } return error_mark_node ; } gcc_assert ( DECL_P ( decl ) || TREE_CODE ( decl ) == OVERLOAD || TREE_CODE ( decl ) == SCOPE_REF || TREE_CODE ( decl ) == UNBOUND_CLASS_TEMPLATE || BASELINK_P ( decl ) ) ; if ( DECL_P ( decl ) ) check_accessibility_of_qualified_id ( decl , object_type , parser -> scope ) ; return decl ; }
Looks up NAME in the current scope, as given by PARSER->SCOPE.
Looks up NAME in the current scope as given by PARSER - > SCOPE .
/* Assume that the lookup will be unambiguous.  */ /* Now that we have looked up the name, the OBJECT_TYPE (if any) is
     no longer valid.  Note that if we are parsing tentatively, and
     the parse fails, OBJECT_TYPE will be automatically restored.  */ /* A template-id has already been resolved; there is no lookup to
     do.  */ /* A BIT_NOT_EXPR is used to represent a destructor.  By this point,
     it should already have been checked to make sure that the name
     used matches the type being destroyed.  */ /* Figure out to which type this destructor applies.  */ /* If that's not a class type, there is no destructor.  */ /* If it was a class type, return the destructor.  */ /* By this point, the NAME should be an ordinary identifier.  If
     the id-expression was a qualified name, the qualifying scope is
     stored in PARSER->SCOPE at this point.  */ /* Perform the lookup.  */ /* If the SCOPE is dependent, the lookup must be deferred until
	 the template is instantiated -- unless we are explicitly
	 looking up names in uninstantiated templates.  Even then, we
	 cannot look up the name if the scope is not a class type; it
	 might, for example, be a template type parameter.  */ /* The resolution to Core Issue 180 says that `struct
		 A::B' should be considered a type-name, even if `A'
		 is dependent.  */ /*complain=*/ /*complain=*/ /*type=*/ /* If PARSER->SCOPE is a dependent type, then it must be a
	     class type, and we must not be checking dependencies;
	     otherwise, we would have processed this lookup above.  So
	     that PARSER->SCOPE is not considered a dependent base by
	     lookup_member, we must enter the scope here.  */ /* If the PARSER->SCOPE is a template specialization, it
	     may be instantiated during name lookup.  In that case,
	     errors may be issued.  Even if we rollback the current
	     tentative parse, those errors are valid.  */ /*complain=*/ /* Look up the name in the scope of the OBJECT_TYPE, unless the
	 OBJECT_TYPE is not a class.  */ /* If the OBJECT_TYPE is a template specialization, it may
	   be instantiated during name lookup.  In that case, errors
	   may be issued.  Even if we rollback the current tentative
	   parse, those errors are valid.  */ /*protect=*/ /* Look it up in the enclosing context, too.  */ /*nonclass=*/ /*block_p=*/ /*nonclass=*/ /*block_p=*/ /* If the lookup failed, let our caller know.  */ /* If it's a TREE_LIST, the result of the lookup was ambiguous.  */ /* The error message we have to print is too complicated for
	 cp_parser_error, so we incorporate its actions directly.  */ /* If we have resolved the name of a member declaration, check to
     see if the declaration is accessible.  When the name resolves to
     set of overloaded functions, accessibility is checked when
     overload resolution is done.

     During an explicit instantiation, access is not checked at all,
     as per [temp.explicit].  */