⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.c

📁 gcc-2.95.3 Linux下最常用的C编译器
💻 C
📖 第 1 页 / 共 5 页
字号:
    type = BINFO_TYPE (binfo);  else if (IS_AGGR_TYPE_CODE (TREE_CODE (binfo)))    {      type = complete_type (binfo);      binfo = TYPE_BINFO (type);      if (path_ptr)	my_friendly_assert (BINFO_INHERITANCE_CHAIN (binfo) == NULL_TREE,			    980827);    }  else    my_friendly_abort (92);  if (parent == type || parent == binfo)    {      /* If the distance is 0, then we don't really need	 a path pointer, but we shouldn't let garbage go back.  */      if (path_ptr)	*path_ptr = binfo;      return 0;    }  if (path_ptr)    watch_access = 1;  rval = get_base_distance_recursive (binfo, 0, 0, -1,				      &rval_private, &new_binfo, parent,				      watch_access, &via_virtual, 0,				      0);  /* Access restrictions don't count if we found an ambiguous basetype.  */  if (rval == -2 && protect >= 0)    rval_private = 0;  if (rval && protect && rval_private)    return -3;  /* If they gave us the real vbase binfo, which isn't in the main binfo     tree, deal with it.  This happens when we are called from     expand_upcast_fixups.  */  if (rval == -1 && TREE_CODE (parent) == TREE_VEC      && parent == binfo_member (BINFO_TYPE (parent),				 CLASSTYPE_VBASECLASSES (type)))    {      my_friendly_assert (BINFO_INHERITANCE_CHAIN (parent) == binfo, 980827);      new_binfo = parent;      rval = 1;    }  if (path_ptr)    *path_ptr = new_binfo;  return rval;}/* Search for a member with name NAME in a multiple inheritance lattice   specified by TYPE.  If it does not exist, return NULL_TREE.   If the member is ambiguously referenced, return `error_mark_node'.   Otherwise, return the FIELD_DECL.  *//* Do a 1-level search for NAME as a member of TYPE.  The caller must   figure out whether it can access this field.  (Since it is only one   level, this is reasonable.)  */static treelookup_field_1 (type, name)     tree type, name;{  register tree field;  if (TREE_CODE (type) == TEMPLATE_TYPE_PARM      || TREE_CODE (type) == TEMPLATE_TEMPLATE_PARM)    /* The TYPE_FIELDS of a TEMPLATE_TYPE_PARM are not fields at all;       instead TYPE_FIELDS is the TEMPLATE_PARM_INDEX.  (Miraculously,       the code often worked even when we treated the index as a list       of fields!)  */    return NULL_TREE;  field = TYPE_FIELDS (type);#ifdef GATHER_STATISTICS  n_calls_lookup_field_1++;#endif /* GATHER_STATISTICS */  while (field)    {#ifdef GATHER_STATISTICS      n_fields_searched++;#endif /* GATHER_STATISTICS */      my_friendly_assert (TREE_CODE_CLASS (TREE_CODE (field)) == 'd', 0);      if (DECL_NAME (field) == NULL_TREE	  && TREE_CODE (TREE_TYPE (field)) == UNION_TYPE)	{	  tree temp = lookup_field_1 (TREE_TYPE (field), name);	  if (temp)	    return temp;	}      if (TREE_CODE (field) == USING_DECL)	/* For now, we're just treating member using declarations as	   old ARM-style access declarations.  Thus, there's no reason	   to return a USING_DECL, and the rest of the compiler can't	   handle it.  Once the class is defined, these are purged	   from TYPE_FIELDS anyhow; see handle_using_decl.  */	;      else if (DECL_NAME (field) == name)	{	  if ((TREE_CODE(field) == VAR_DECL || TREE_CODE(field) == CONST_DECL)	      && DECL_ASSEMBLER_NAME (field) != NULL)	    GNU_xref_ref(current_function_decl,			 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (field)));	  return field;	}      field = TREE_CHAIN (field);    }  /* Not found.  */  if (name == _vptr_name)    {      /* Give the user what s/he thinks s/he wants.  */      if (TYPE_VIRTUAL_P (type))	return CLASSTYPE_VFIELD (type);    }  return NULL_TREE;}/* There are a number of cases we need to be aware of here:			 current_class_type	current_function_decl     global			NULL			NULL     fn-local			NULL			SET     class-local		SET			NULL     class->fn			SET			SET     fn->class			SET			SET   Those last two make life interesting.  If we're in a function which is   itself inside a class, we need decls to go into the fn's decls (our   second case below).  But if we're in a class and the class itself is   inside a function, we need decls to go into the decls for the class.  To   achieve this last goal, we must see if, when both current_class_ptr and   current_function_decl are set, the class was declared inside that   function.  If so, we know to put the decls into the class's scope.  */treecurrent_scope (){  if (current_function_decl == NULL_TREE)    return current_class_type;  if (current_class_type == NULL_TREE)    return current_function_decl;  if (DECL_CLASS_CONTEXT (current_function_decl) == current_class_type)    return current_function_decl;  return current_class_type;}/* Return the scope of DECL, as appropriate when doing name-lookup.  */static treecontext_for_name_lookup (decl)     tree decl;{  /* [class.union]          For the purposes of name lookup, after the anonymous union     definition, the members of the anonymous union are considered to     have been defined in the scope in which teh anonymous union is     declared.  */   tree context = DECL_REAL_CONTEXT (decl);  while (TYPE_P (context) && ANON_UNION_TYPE_P (context))    context = TYPE_CONTEXT (context);  if (!context)    context = global_namespace;  return context;}/* Return a canonical BINFO if BINFO is a virtual base, or just BINFO   otherwise.  */static treecanonical_binfo (binfo)     tree binfo;{  return (TREE_VIA_VIRTUAL (binfo)	  ? TYPE_BINFO (BINFO_TYPE (binfo)) : binfo);}/* A queue function that simply ensures that we walk into the   canonical versions of virtual bases.  */static treedfs_canonical_queue (binfo, data)     tree binfo;     void *data ATTRIBUTE_UNUSED;{  return canonical_binfo (binfo);}/* Called via dfs_walk from assert_canonical_unmarked.  */static treedfs_assert_unmarked_p (binfo, data)     tree binfo;     void *data ATTRIBUTE_UNUSED;{  my_friendly_assert (!BINFO_MARKED (binfo), 0);  return NULL_TREE;}/* Asserts that all the nodes below BINFO (using the canonical   versions of virtual bases) are unmarked.  */static voidassert_canonical_unmarked (binfo)     tree binfo;{  dfs_walk (binfo, dfs_assert_unmarked_p, dfs_canonical_queue, 0);}/* If BINFO is marked, return a canonical version of BINFO.   Otherwise, return NULL_TREE.  */static treeshared_marked_p (binfo, data)     tree binfo;     void *data;{  binfo = canonical_binfo (binfo);  return markedp (binfo, data) ? binfo : NULL_TREE;}/* If BINFO is not marked, return a canonical version of BINFO.   Otherwise, return NULL_TREE.  */static treeshared_unmarked_p (binfo, data)     tree binfo;     void *data;{  binfo = canonical_binfo (binfo);  return unmarkedp (binfo, data) ? binfo : NULL_TREE;}/* Called from access_in_type via dfs_walk.  Calculate the access to   DATA (which is really a DECL) in BINFO.  */static treedfs_access_in_type (binfo, data)     tree binfo;     void *data;{  tree decl = (tree) data;  tree type = BINFO_TYPE (binfo);  tree access = NULL_TREE;  if (context_for_name_lookup (decl) == type)    {      /* If we have desceneded to the scope of DECL, just note the	 appropriate access.  */      if (TREE_PRIVATE (decl))	access = access_private_node;      else if (TREE_PROTECTED (decl))	access = access_protected_node;      else	access = access_public_node;    }  else     {      /* First, check for an access-declaration that gives us more	 access to the DECL.  The CONST_DECL for an enumeration	 constant will not have DECL_LANG_SPECIFIC, and thus no	 DECL_ACCESS.  */      if (DECL_LANG_SPECIFIC (decl))	{	  access = purpose_member (type, DECL_ACCESS (decl));	  if (access)	    access = TREE_VALUE (access);	}      if (!access)	{	  int i;	  int n_baselinks;	  tree binfos;	  	  /* Otherwise, scan our baseclasses, and pick the most favorable	     access.  */	  binfos = BINFO_BASETYPES (binfo);	  n_baselinks = binfos ? TREE_VEC_LENGTH (binfos) : 0;	  for (i = 0; i < n_baselinks; ++i)	    {	      tree base_binfo = TREE_VEC_ELT (binfos, i);	      tree base_access = TREE_CHAIN (canonical_binfo (base_binfo));	      if (!base_access || base_access == access_private_node)		/* If it was not accessible in the base, or only		   accessible as a private member, we can't access it		   all.  */		base_access = NULL_TREE;	      else if (TREE_VIA_PROTECTED (base_binfo))		/* Public and protected members in the base are		   protected here.  */		base_access = access_protected_node;	      else if (!TREE_VIA_PUBLIC (base_binfo))		/* Public and protected members in the base are		   private here.  */		base_access = access_private_node;	      /* See if the new access, via this base, gives more		 access than our previous best access.  */	      if (base_access &&		  (base_access == access_public_node		   || (base_access == access_protected_node		       && access != access_public_node)		   || (base_access == access_private_node		       && !access)))		{		  access = base_access;		  /* If the new access is public, we can't do better.  */		  if (access == access_public_node)		    break;		}	    }	}    }  /* Note the access to DECL in TYPE.  */  TREE_CHAIN (binfo) = access;  /* Mark TYPE as visited so that if we reach it again we do not     duplicate our efforts here.  */  SET_BINFO_MARKED (binfo);  return NULL_TREE;}/* Return the access to DECL in TYPE.  */static tree access_in_type (type, decl)     tree type;     tree decl;{  tree binfo = TYPE_BINFO (type);  /* We must take into account       [class.paths]       If a name can be reached by several paths through a multiple       inheritance graph, the access is that of the path that gives       most access.      The algorithm we use is to make a post-order depth-first traversal    of the base-class hierarchy.  As we come up the tree, we annotate    each node with the most lenient access.  */  dfs_walk_real (binfo, 0, dfs_access_in_type, shared_unmarked_p, decl);  dfs_walk (binfo, dfs_unmark, shared_marked_p,  0);  assert_canonical_unmarked (binfo);  return TREE_CHAIN (binfo);}/* Called from dfs_accessible_p via dfs_walk.  */static treedfs_accessible_queue_p (binfo, data)     tree binfo;     void *data ATTRIBUTE_UNUSED;{  if (BINFO_MARKED (binfo))    return NULL_TREE;  /* If this class is inherited via private or protected inheritance,     then we can't see it, unless we are a friend of the subclass.  */  if (!TREE_VIA_PUBLIC (binfo)      && !is_friend (BINFO_TYPE (BINFO_INHERITANCE_CHAIN (binfo)),		     current_scope ()))    return NULL_TREE;  return canonical_binfo (binfo);}/* Called from dfs_accessible_p via dfs_walk.  */static treedfs_accessible_p (binfo, data)     tree binfo;     void *data;{  int protected_ok = data != 0;  tree access;  /* We marked the binfos while computing the access in each type.     So, we unmark as we go now.  */  SET_BINFO_MARKED (binfo);  access = TREE_CHAIN (binfo);  if (access == access_public_node      || (access == access_protected_node && protected_ok))    return binfo;  else if (access && is_friend (BINFO_TYPE (binfo), current_scope ()))    return binfo;  return NULL_TREE;}/* Returns non-zero if it is OK to access DECL when named in TYPE   through an object indiated by BINFO in the context of DERIVED.  */static intprotected_accessible_p (type, decl, derived, binfo)     tree type;     tree decl;     tree derived;     tree binfo;{  tree access;  /* We're checking this clause from [class.access.base]       m as a member of N is protected, and the reference occurs in a       member or friend of class N, or in a member or friend of a       class P derived from N, where m as a member of P is private or       protected.      If DERIVED isn't derived from TYPE, then it certainly does not    apply.  */  if (!DERIVED_FROM_P (type, derived))    return 0;  access = access_in_type (derived, decl);  if (same_type_p (derived, type))    {      if (access != access_private_node)	return 0;    }  else if (access != access_private_node	   && access != access_protected_node)    return 0;    /* [class.protected]     When a friend or a member function of a derived class references     a protected nonstatic member of a base class, an access check     applies in addition to those described earlier in clause     _class.access_.4) Except when forming a pointer to member     (_expr.unary.op_), the access must be through a pointer to,     reference to, or object of the derived class itself (or any class     derived from that class) (_expr.ref_).  If the access is to form     a pointer to member, the nested-name-specifier shall name the     derived class (or any class derived from that class).  */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -