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]
Other format: [Raw text]

[C++ PATCH] die hack_identifier, die!


Hi,
In working on fixing 9447, I fell into hack_identifer. That can be killed
now we have a sensible parser - yay!

In folding into its only remaining caller, I simplified what remains,
I believe those transformations are safe.

booted & tested on i686-pc-linux-gnu, ok?

nathan
--
Nathan Sidwell    ::   http://www.codesourcery.com   ::     CodeSourcery LLC
         The voices in my head said this was stupid too
nathan@codesourcery.com    ::     http://www.planetfall.pwp.blueyonder.co.uk

2003-07-18  Nathan Sidwell  <nathan@codesourcery.com>

	* cp-tree.h (hack_identifier): Remove.
	* method.c (hack_identifier): Remove.
	* semantics.c (finish_id_expression): Expand hack_identifier
	here. Simplify.

Index: cp/cp-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/cp-tree.h,v
retrieving revision 1.881
diff -c -3 -p -r1.881 cp-tree.h
*** cp/cp-tree.h	18 Jul 2003 17:19:39 -0000	1.881
--- cp/cp-tree.h	18 Jul 2003 17:31:00 -0000
*************** extern void cxx_finish (void);
*** 3923,3929 ****
  /* in method.c */
  extern void init_method	(void);
  extern void set_mangled_name_for_decl (tree);
- extern tree hack_identifier (tree, tree);
  extern tree make_thunk (tree, bool, tree, tree);
  extern void finish_thunk (tree);
  extern void use_thunk (tree, bool);
--- 3924,3929 ----
Index: cp/method.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/method.c,v
retrieving revision 1.261
diff -c -3 -p -r1.261 method.c
*** cp/method.c	18 Jul 2003 17:19:40 -0000	1.261
--- cp/method.c	18 Jul 2003 17:31:03 -0000
*************** set_mangled_name_for_decl (tree decl)
*** 88,206 ****
  }
  
  
- /* This function takes an identifier, ID, and attempts to figure out what
-    it means. There are a number of possible scenarios, presented in increasing
-    order of hair:
- 
-    1) not in a class's scope
-    2) in class's scope, member name of the class's method
-    3) in class's scope, but not a member name of the class
-    4) in class's scope, member name of a class's variable
- 
-    NAME is $1 from the bison rule. It is an IDENTIFIER_NODE.
-    VALUE is $$ from the bison rule. It is the value returned by lookup_name ($1)
- 
-    As a last ditch, try to look up the name as a label and return that
-    address.
- 
-    Values which are declared as being of REFERENCE_TYPE are
-    automatically dereferenced here (as a hack to make the
-    compiler faster).  */
- 
- tree
- hack_identifier (tree value, tree name)
- {
-   tree type;
- 
-   if (value == error_mark_node)
-     return error_mark_node;
- 
-   type = TREE_TYPE (value);
-   if (TREE_CODE (value) == FIELD_DECL)
-     value = finish_non_static_data_member (value, current_class_ref,
- 					   /*qualifying_scope=*/NULL_TREE);
-   else if ((TREE_CODE (value) == FUNCTION_DECL
- 	    && DECL_FUNCTION_MEMBER_P (value))
- 	   || (TREE_CODE (value) == OVERLOAD
- 	       && DECL_FUNCTION_MEMBER_P (OVL_CURRENT (value))))
-     {
-       tree decl;
- 
-       if (TREE_CODE (value) == OVERLOAD)
- 	value = OVL_CURRENT (value);
- 
-       decl = maybe_dummy_object (DECL_CONTEXT (value), 0);
-       value = finish_class_member_access_expr (decl, name);
-     }
-   else if (really_overloaded_fn (value))
-     ;
-   else if (TREE_CODE (value) == OVERLOAD)
-     /* not really overloaded function */
-     mark_used (OVL_FUNCTION (value));
-   else if (TREE_CODE (value) == TREE_LIST)
-     {
-       /* Ambiguous reference to base members, possibly other cases?.  */
-       tree t = value;
-       while (t && TREE_CODE (t) == TREE_LIST)
- 	{
- 	  mark_used (TREE_VALUE (t));
- 	  t = TREE_CHAIN (t);
- 	}
-     }
-   else if (TREE_CODE (value) == NAMESPACE_DECL)
-     {
-       error ("use of namespace `%D' as expression", value);
-       return error_mark_node;
-     }
-   else if (DECL_CLASS_TEMPLATE_P (value))
-     {
-       error ("use of class template `%T' as expression", value);
-       return error_mark_node;
-     }
-   else
-     mark_used (value);
- 
-   if (TREE_CODE (value) == VAR_DECL || TREE_CODE (value) == PARM_DECL
-       || TREE_CODE (value) == RESULT_DECL)
-     {
-       tree context = decl_function_context (value);
-       if (context != NULL_TREE && context != current_function_decl
- 	  && ! TREE_STATIC (value))
- 	{
- 	  error ("use of %s from containing function",
- 		      (TREE_CODE (value) == VAR_DECL
- 		       ? "`auto' variable" : "parameter"));
- 	  cp_error_at ("  `%#D' declared here", value);
- 	  value = error_mark_node;
- 	}
-     }
- 
-   if (DECL_P (value) && DECL_NONLOCAL (value))
-     {
-       if (DECL_CLASS_SCOPE_P (value)
- 	  && DECL_CONTEXT (value) != current_class_type)
- 	{
- 	  tree path;
- 	  path = currently_open_derived_class (DECL_CONTEXT (value));
- 	  perform_or_defer_access_check (TYPE_BINFO (path), value);
- 	}
-     }
-   else if (TREE_CODE (value) == TREE_LIST 
- 	   && TREE_TYPE (value) == error_mark_node)
-     {
-       error ("\
- request for member `%D' is ambiguous in multiple inheritance lattice",
- 		name);
-       print_candidates (value);
-       return error_mark_node;
-     }
- 
-   if (! processing_template_decl)
-     value = convert_from_reference (value);
-   return value;
- }
- 
- 
  /* Return a this or result adjusting thunk to FUNCTION.  THIS_ADJUSTING
     indicates whether it is a this or result adjusting thunk.
     FIXED_OFFSET and VIRTUAL_OFFSET indicate how to do the adjustment
--- 88,93 ----
Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.330
diff -c -3 -p -r1.330 semantics.c
*** cp/semantics.c	18 Jul 2003 17:19:40 -0000	1.330
--- cp/semantics.c	18 Jul 2003 17:31:35 -0000
*************** finish_id_expression (tree id_expression
*** 2522,2532 ****
  	  else if (TYPE_P (scope))
  	    decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl);
  	}
!       else
! 	/* Transform references to non-static data members into
! 	   COMPONENT_REFs.  */
! 	decl = hack_identifier (decl, id_expression);
  
        /* Resolve references to variables of anonymous unions
  	 into COMPONENT_REFs.  */
        if (TREE_CODE (decl) == ALIAS_DECL)
--- 2522,2601 ----
  	  else if (TYPE_P (scope))
  	    decl = build (SCOPE_REF, TREE_TYPE (decl), scope, decl);
  	}
!       else if (TREE_CODE (decl) == NAMESPACE_DECL)
! 	{
! 	  error ("use of namespace `%D' as expression", decl);
! 	  return error_mark_node;
! 	}
!       else if (DECL_CLASS_TEMPLATE_P (decl))
! 	{
! 	  error ("use of class template `%T' as expression", decl);
! 	  return error_mark_node;
! 	}
!       else if (TREE_CODE (decl) == TREE_LIST)
! 	{
! 	  /* Ambiguous reference to base members.  */
! 	  error ("request for member `%D' is ambiguous in "
! 		 "multiple inheritance lattice", id_expression);
! 	  print_candidates (decl);
! 	  return error_mark_node;
! 	}
!       else if (TREE_CODE (decl) == FIELD_DECL)
! 	decl = finish_non_static_data_member (decl, current_class_ref,
! 					      /*qualifying_scope=*/NULL_TREE);
!       else if (is_overloaded_fn (decl))
! 	{
! 	  tree first_fn = OVL_CURRENT (decl);
  
+ 	  if (TREE_CODE (first_fn) == TEMPLATE_DECL)
+ 	    first_fn = DECL_TEMPLATE_RESULT (first_fn);
+ 	  
+ 	  if (TREE_CODE (first_fn) == FUNCTION_DECL
+ 	      && DECL_FUNCTION_MEMBER_P (first_fn))
+ 	    {
+ 	      /* A set of member functions.  */
+ 	      decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
+ 	      return finish_class_member_access_expr (decl, id_expression);
+ 	    }
+ 	  else if (!really_overloaded_fn (decl))
+ 	    /* not really overloaded function */
+ 	    mark_used (first_fn);
+ 	}
+       else
+ 	{
+ 	  if (TREE_CODE (decl) == VAR_DECL
+ 	      || TREE_CODE (decl) == PARM_DECL
+ 	      || TREE_CODE (decl) == RESULT_DECL)
+ 	    {
+ 	      tree context = decl_function_context (decl);
+ 	      
+ 	      if (context != NULL_TREE && context != current_function_decl
+ 		  && ! TREE_STATIC (decl))
+ 		{
+ 		  error ("use of %s from containing function",
+ 			 (TREE_CODE (decl) == VAR_DECL
+ 			  ? "`auto' variable" : "parameter"));
+ 		  cp_error_at ("  `%#D' declared here", decl);
+ 		  return error_mark_node;
+ 		}
+ 	    }
+ 	  
+ 	  if (DECL_P (decl) && DECL_NONLOCAL (decl)
+ 	      && DECL_CLASS_SCOPE_P (decl)
+ 	      && DECL_CONTEXT (decl) != current_class_type)
+ 	    {
+ 	      tree path;
+ 	      
+ 	      path = currently_open_derived_class (DECL_CONTEXT (decl));
+ 	      perform_or_defer_access_check (TYPE_BINFO (path), decl);
+ 	    }
+ 	  
+ 	  mark_used (decl);
+ 	  
+ 	  if (! processing_template_decl)
+ 	    decl = convert_from_reference (decl);
+ 	}
+       
        /* Resolve references to variables of anonymous unions
  	 into COMPONENT_REFs.  */
        if (TREE_CODE (decl) == ALIAS_DECL)

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