This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Cleanup: binding_for_name, my_tree_cons


These are two minor changes that should not change the behaviour at
all, just the readability. We can discuss them separately if desired.

The first one restores the gcc 2.8 code; the optimization of keeping
the binding is not necessary anymore, as the binding accessed last is
moved to the front of the list (in case there is a list at all, *).

The my_tree_cons change uses the common 'switch obstacks' approach
instead of hacking together list nodes directly. I also changed the
name, because my_ is not a very good function name prefix.

Martin

(*) I was hoping that this also activates the optimization that a
single global value is stored without a CPLUS_BINDING. Unfortunately,
unqualified lookup retrieves the binding, as there might be a global
type. I'll look into that.

1998-08-22  Martin von Löwis  <loewis@informatik.hu-berlin.de>

	* decl.c (pushdecl): Use IDENTIFIER_NAMESPACE_VALUE instead of
	accessing bindings directly.

	* search.c (my_tree_cons): Rename to toe_tree_cons. Reimplement.
	(make_memoized_table_entry, lookup_field, lookup_fnfields):
	Change callers.
	
Index: decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/decl.c,v
retrieving revision 1.184
diff -c -p -r1.184 decl.c
*** decl.c	1998/08/20 17:41:39	1.184
--- decl.c	1998/08/22 14:11:44
*************** pushdecl (x)
*** 3508,3519 ****
        if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
  	{
  	  tree decl;
- 	  tree bindings = binding_for_name (name, current_namespace);
  
! 	  if (BINDING_VALUE (bindings) != NULL_TREE
! 	      && (DECL_EXTERNAL (BINDING_VALUE (bindings))
! 		  || TREE_PUBLIC (BINDING_VALUE (bindings))))
! 	    decl = BINDING_VALUE (bindings);
  	  else
  	    decl = NULL_TREE;
  
--- 3508,3518 ----
        if (TREE_PUBLIC (x) && TREE_CODE (x) != FUNCTION_DECL)
  	{
  	  tree decl;
  
! 	  if (IDENTIFIER_NAMESPACE_VALUE (name) != NULL_TREE
! 	      && (DECL_EXTERNAL (IDENTIFIER_NAMESPACE_VALUE (name))
! 		  || TREE_PUBLIC (IDENTIFIER_NAMESPACE_VALUE (name))))
! 	    decl = IDENTIFIER_NAMESPACE_VALUE (name);
  	  else
  	    decl = NULL_TREE;
  
*************** pushdecl (x)
*** 3532,3542 ****
        if (namespace_bindings_p ())
  	{
  	  /* Install a global value.  */
- 	  tree bindings = binding_for_name (name, current_namespace);
  
  	  /* If the first global decl has external linkage,
  	     warn if we later see static one.  */
! 	  if (BINDING_VALUE (bindings) == NULL_TREE && TREE_PUBLIC (x))
  	    TREE_PUBLIC (name) = 1;
  
  	  /* Don't install an artificial TYPE_DECL if we already have
--- 3531,3540 ----
        if (namespace_bindings_p ())
  	{
  	  /* Install a global value.  */
  
  	  /* If the first global decl has external linkage,
  	     warn if we later see static one.  */
! 	  if (IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE && TREE_PUBLIC (x))
  	    TREE_PUBLIC (name) = 1;
  
  	  /* Don't install an artificial TYPE_DECL if we already have
*************** pushdecl (x)
*** 3546,3554 ****
  	      || ! DECL_ARTIFICIAL (x))
  	    {
  	      if (TREE_CODE (x) == FUNCTION_DECL)
! 		my_friendly_assert ((BINDING_VALUE (bindings) == NULL_TREE)
! 		                    || BINDING_VALUE (bindings) == x, 378);
! 	      BINDING_VALUE (bindings) = x;
  	    }
  
  	  /* Don't forget if the function was used via an implicit decl.  */
--- 3544,3553 ----
  	      || ! DECL_ARTIFICIAL (x))
  	    {
  	      if (TREE_CODE (x) == FUNCTION_DECL)
! 		my_friendly_assert 
! 		  ((IDENTIFIER_GLOBAL_VALUE (name) == NULL_TREE)
! 		  || (IDENTIFIER_GLOBAL_VALUE (name) == x), 378);
! 	      SET_IDENTIFIER_NAMESPACE_VALUE (name, x);
  	    }
  
  	  /* Don't forget if the function was used via an implicit decl.  */
*************** pushdecl (x)
*** 3578,3584 ****
  	{
  	  /* Here to install a non-global value.  */
  	  tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
! 	  tree oldglobal = binding_for_name (name, current_namespace);
  
  	  /* Don't install an artificial TYPE_DECL if we already have
  	     another _DECL with that name.  */
--- 3577,3583 ----
  	{
  	  /* Here to install a non-global value.  */
  	  tree oldlocal = IDENTIFIER_LOCAL_VALUE (name);
! 	  tree oldglobal = IDENTIFIER_NAMESPACE_VALUE (name);
  
  	  /* Don't install an artificial TYPE_DECL if we already have
  	     another _DECL with that name.  */
*************** pushdecl (x)
*** 3601,3624 ****
  	     have a global definition or declaration for the function.  */
  	  if (oldlocal == NULL_TREE
  	      && DECL_EXTERNAL (x)
! 	      && BINDING_VALUE (oldglobal) != NULL_TREE
  	      && TREE_CODE (x) == FUNCTION_DECL
! 	      && TREE_CODE (BINDING_VALUE (oldglobal)) == FUNCTION_DECL)
  	    {
  	      /* We have one.  Their types must agree.  */
! 	      if (decls_match (x, BINDING_VALUE (oldglobal)))
  		/* OK */;
  	      else
  		{
  		  cp_warning ("extern declaration of `%#D' doesn't match", x);
! 		  cp_warning_at ("global declaration `%#D'", BINDING_VALUE (oldglobal));
  		}
  	    }
  	  /* If we have a local external declaration,
  	     and no file-scope declaration has yet been seen,
  	     then if we later have a file-scope decl it must not be static.  */
  	  if (oldlocal == NULL_TREE
! 	      && BINDING_VALUE (oldglobal) == NULL_TREE
  	      && DECL_EXTERNAL (x)
  	      && TREE_PUBLIC (x))
  	    {
--- 3600,3623 ----
  	     have a global definition or declaration for the function.  */
  	  if (oldlocal == NULL_TREE
  	      && DECL_EXTERNAL (x)
! 	      && oldglobal != NULL_TREE
  	      && TREE_CODE (x) == FUNCTION_DECL
! 	      && TREE_CODE (oldglobal) == FUNCTION_DECL)
  	    {
  	      /* We have one.  Their types must agree.  */
! 	      if (decls_match (x, oldglobal))
  		/* OK */;
  	      else
  		{
  		  cp_warning ("extern declaration of `%#D' doesn't match", x);
! 		  cp_warning_at ("global declaration `%#D'", oldglobal);
  		}
  	    }
  	  /* If we have a local external declaration,
  	     and no file-scope declaration has yet been seen,
  	     then if we later have a file-scope decl it must not be static.  */
  	  if (oldlocal == NULL_TREE
! 	      && oldglobal == NULL_TREE
  	      && DECL_EXTERNAL (x)
  	      && TREE_PUBLIC (x))
  	    {
*************** pushdecl (x)
*** 3668,3674 ****
  		warnstring = "declaration of `%s' shadows a member of `this'";
  	      else if (oldlocal != NULL_TREE)
  		warnstring = "declaration of `%s' shadows previous local";
! 	      else if (BINDING_VALUE (oldglobal) != NULL_TREE)
  		/* XXX shadow warnings in outer-more namespaces */
  		warnstring = "declaration of `%s' shadows global declaration";
  
--- 3667,3673 ----
  		warnstring = "declaration of `%s' shadows a member of `this'";
  	      else if (oldlocal != NULL_TREE)
  		warnstring = "declaration of `%s' shadows previous local";
! 	      else if (oldglobal != NULL_TREE)
  		/* XXX shadow warnings in outer-more namespaces */
  		warnstring = "declaration of `%s' shadows global declaration";
  
*************** lookup_tag (form, name, binding_level, t
*** 4510,4516 ****
  	  }
        else if (level->namespace_p)
  	/* Do namespace lookup. */
- 	/* XXX: is this a real lookup, considering using-directives etc. ??? */
  	for (tail = current_namespace; 1; tail = CP_DECL_CONTEXT (tail))
  	  {
  	    tree old = binding_for_name (name, tail);
--- 4509,4514 ----
Index: search.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/search.c,v
retrieving revision 1.40
diff -c -p -r1.40 search.c
*** search.c	1998/08/03 22:11:24	1.40
--- search.c	1998/08/22 14:12:22
*************** static struct type_level *push_type_leve
*** 140,146 ****
  	PROTO((struct stack_level *, struct obstack *));
  static struct type_level *pop_type_level
  	PROTO((struct type_level *));
! static tree my_tree_cons PROTO((tree, tree, tree));
  static tree my_build_string PROTO((char *));
  static struct memoized_entry * my_new_memoized_entry
  	PROTO((struct memoized_entry *));
--- 140,146 ----
  	PROTO((struct stack_level *, struct obstack *));
  static struct type_level *pop_type_level
  	PROTO((struct type_level *));
! static tree toe_tree_cons PROTO((tree, tree, tree));
  static tree my_build_string PROTO((char *));
  static struct memoized_entry * my_new_memoized_entry
  	PROTO((struct memoized_entry *));
*************** pop_type_level (stack)
*** 258,273 ****
     do it on the type_obstack_entries obstack.  */
  
  static tree
! my_tree_cons (purpose, value, chain)
       tree purpose, value, chain;
  {
!   tree p = (tree)obstack_alloc (&type_obstack_entries, sizeof (struct tree_list));
!   bzero ((char *)p, sizeof (struct tree_list));
!   ++my_tree_node_counter;
!   TREE_SET_CODE (p, TREE_LIST);
!   TREE_PURPOSE (p) = purpose;
!   TREE_VALUE (p) = value;
!   TREE_CHAIN (p) = chain;
    return p;
  }
  
--- 258,271 ----
     do it on the type_obstack_entries obstack.  */
  
  static tree
! toe_tree_cons (purpose, value, chain)
       tree purpose, value, chain;
  {
!   struct obstack *ambient_obstack = current_obstack;
!   tree p;
!   current_obstack = &type_obstack_entries;
!   p = tree_cons (purpose, value, chain);
!   current_obstack = ambient_obstack;
    return p;
  }
  
*************** make_memoized_table_entry (type, name, f
*** 360,366 ****
    else
      prev_entry = &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
  
!   entry = my_tree_cons (name, NULL_TREE, *prev_entry);
    *prev_entry = entry;
  
    /* Don't know the error message to give yet.  */
--- 358,364 ----
    else
      prev_entry = &MEMOIZED_FIELDS (CLASSTYPE_MTABLE_ENTRY (type), idx);
  
!   entry = toe_tree_cons (name, NULL_TREE, *prev_entry);
    *prev_entry = entry;
  
    /* Don't know the error message to give yet.  */
*************** lookup_field (xbasetype, name, protect, 
*** 1342,1357 ****
  	      tree btypes;
  
  	      SET_BINFO_FIELDS_MARKED (base_binfo);
! 	      btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain);
  	      TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
  	      TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
  	      TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
  	      if (TREE_VIA_VIRTUAL (base_binfo))
! 		btypes = my_tree_cons (NULL_TREE,
  				    TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
  				    btypes);
  	      else
! 		btypes = my_tree_cons (NULL_TREE,
  				    TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
  				    btypes);
  	      obstack_ptr_grow (&search_obstack, btypes);
--- 1340,1355 ----
  	      tree btypes;
  
  	      SET_BINFO_FIELDS_MARKED (base_binfo);
! 	      btypes = toe_tree_cons (NULL_TREE, base_binfo, basetype_chain);
  	      TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
  	      TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
  	      TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
  	      if (TREE_VIA_VIRTUAL (base_binfo))
! 		btypes = toe_tree_cons (NULL_TREE,
  				    TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
  				    btypes);
  	      else
! 		btypes = toe_tree_cons (NULL_TREE,
  				    TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
  				    btypes);
  	      obstack_ptr_grow (&search_obstack, btypes);
*************** lookup_fnfields (basetype_path, name, co
*** 1825,1831 ****
    if (idx >= 0)
      {
        rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
!       rvals = my_tree_cons (basetype_path, rval, rvals);
        if (BINFO_BASETYPES (binfo) && CLASSTYPE_BASELINK_VEC (type))
  	TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
  
--- 1823,1829 ----
    if (idx >= 0)
      {
        rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
!       rvals = toe_tree_cons (basetype_path, rval, rvals);
        if (BINFO_BASETYPES (binfo) && CLASSTYPE_BASELINK_VEC (type))
  	TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
  
*************** lookup_fnfields (basetype_path, name, co
*** 1885,1900 ****
  	      tree btypes;
  
  	      SET_BINFO_FIELDS_MARKED (base_binfo);
! 	      btypes = my_tree_cons (NULL_TREE, base_binfo, basetype_chain);
  	      TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
  	      TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
  	      TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
  	      if (TREE_VIA_VIRTUAL (base_binfo))
! 		btypes = my_tree_cons (NULL_TREE,
  				    TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
  				    btypes);
  	      else
! 		btypes = my_tree_cons (NULL_TREE,
  				    TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
  				    btypes);
  	      obstack_ptr_grow (&search_obstack, btypes);
--- 1883,1898 ----
  	      tree btypes;
  
  	      SET_BINFO_FIELDS_MARKED (base_binfo);
! 	      btypes = toe_tree_cons (NULL_TREE, base_binfo, basetype_chain);
  	      TREE_VIA_PUBLIC (btypes) = TREE_VIA_PUBLIC (base_binfo);
  	      TREE_VIA_PROTECTED (btypes) = TREE_VIA_PROTECTED (base_binfo);
  	      TREE_VIA_VIRTUAL (btypes) = TREE_VIA_VIRTUAL (base_binfo);
  	      if (TREE_VIA_VIRTUAL (base_binfo))
! 		btypes = toe_tree_cons (NULL_TREE,
  				    TYPE_BINFO (BINFO_TYPE (TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i))),
  				    btypes);
  	      else
! 		btypes = toe_tree_cons (NULL_TREE,
  				    TREE_VEC_ELT (BINFO_BASETYPES (binfo_h), i),
  				    btypes);
  	      obstack_ptr_grow (&search_obstack, btypes);
*************** lookup_fnfields (basetype_path, name, co
*** 1942,1948 ****
  		  rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
  		  /* Note, rvals can only be previously set if find_all is
  		     true.  */
! 		  rvals = my_tree_cons (basetype_path, rval, rvals);
  		  if (TYPE_BINFO_BASETYPES (type)
  		      && CLASSTYPE_BASELINK_VEC (type))
  		    TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);
--- 1940,1946 ----
  		  rval = TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (type), idx);
  		  /* Note, rvals can only be previously set if find_all is
  		     true.  */
! 		  rvals = toe_tree_cons (basetype_path, rval, rvals);
  		  if (TYPE_BINFO_BASETYPES (type)
  		      && CLASSTYPE_BASELINK_VEC (type))
  		    TREE_TYPE (rvals) = TREE_VEC_ELT (CLASSTYPE_BASELINK_VEC (type), idx);



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]