[PATCH]: Coping with a clean method DECL_NAMEs.

Alexandre Petit-Bianco apbianco@cygnus.com
Thu Jan 25 14:22:00 GMT 2001


I wrote a patch to get rid of the code that was accounting for a
sometimes WFLed method DECL_NAMEs, since they're now back to their
original value (IDENTIFIER_POINTER.) I couldn't find regressions
testing it, I'm checking this in, because otherwise the compiler might
crash trying to report some errors.

./A

2001-01-25  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* ChangeLog (2001-01-21): Fixed typo.
	* class.c (layout_class_method): Code accounting for WFLed
	method DECL_NAMEs deleted.
	* constant.c (find_methodref_index): Likewise.
	* decl.c (lang_mark_tree): Mark `wfl' field in struct lang_decl.
	* java-tree.h (DECL_FUNCTION_WFL): New macro.
	(struct lang_decl): New field `wfl'.
	(java_get_real_method_name): Prototype deleted.
	* mangle.c (mangle_method_decl): Code accounting for WFLed
	method DECL_NAMEs deleted.
	* parse.h (GET_METHOD_NAME): Macro deleted.
	* parse.y (reset_method_name): Deleted.
	(method_header): Set DECL_FUNCTION_WFL.
	(check_abstract_method_header): Code accounting for WFLed method
	DECL_NAMEs deleted.
	(java_get_real_method_name): Deleted.
	(check_method_redefinition): Code accounting for WFLed method
	DECL_NAMEs deleted. Use DECL_FUNCTION_WFL.
	(java_check_regular_methods): Likewise.
	(java_check_abstract_methods): Likewise.
	(java_expand_classes): Don't call `reset_method_name.'
	(search_applicable_method_list): Use DECL_NAMEs instead of
	GET_METHOD_NAME.
	* typeck.c (lookup_do): Code accounting for WFLed method
	DECL_NAMEs deleted.

Index: class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/class.c,v
retrieving revision 1.86
diff -u -p -r1.86 class.c
--- class.c	2001/01/24 08:08:36	1.86
+++ class.c	2001/01/25 21:28:12
@@ -1773,10 +1773,6 @@ layout_class_method (this_class, super_c
      tree this_class, super_class, method_decl, dtable_count;
 {
   tree method_name = DECL_NAME (method_decl);
-  int method_name_is_wfl = 
-    (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION);
-  if (method_name_is_wfl)
-    method_name = java_get_real_method_name (method_decl);
 
   TREE_PUBLIC (method_decl) = 1;
 
@@ -1799,10 +1795,6 @@ layout_class_method (this_class, super_c
 	  if (*ptr++ == '.')
 	    p = ptr;
 	}
-      if (method_name_is_wfl)
-	EXPR_WFL_NODE (DECL_NAME (method_decl)) = get_identifier (p);
-      else
-	DECL_NAME (method_decl) = get_identifier (p);
       DECL_CONSTRUCTOR_P (method_decl) = 1;
       build_java_argument_signature (TREE_TYPE (method_decl));
     }
Index: constants.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/constants.c,v
retrieving revision 1.15
diff -u -p -r1.15 constants.c
--- constants.c	2001/01/10 23:06:30	1.15
+++ constants.c	2001/01/25 21:28:13
@@ -202,8 +202,6 @@ find_methodref_index (cpool, decl)
   tree name = DECL_CONSTRUCTOR_P (decl) ? init_identifier_node
     : DECL_NAME (decl);
   int name_type_index;
-  if (TREE_CODE (name) == EXPR_WITH_FILE_LOCATION)
-    name = EXPR_WFL_NODE (name);    
   name_type_index = 
       find_name_and_type_constant (cpool, name, TREE_TYPE (decl));
   return find_constant1 (cpool,
Index: decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/decl.c,v
retrieving revision 1.83
diff -u -p -r1.83 decl.c
--- decl.c	2001/01/15 08:01:21	1.83
+++ decl.c	2001/01/25 21:28:18
@@ -1920,6 +1920,7 @@ lang_mark_tree (t)
       if (ld)
 	{
 	  ggc_mark (ld);
+	  ggc_mark_tree (ld->wfl);
 	  ggc_mark_tree (ld->throws_list);
 	  ggc_mark_tree (ld->function_decl_body);
 	  ggc_mark_tree (ld->called_constructor);
Index: java-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.93
diff -u -p -r1.93 java-tree.h
--- java-tree.h	2001/01/15 08:01:21	1.93
+++ java-tree.h	2001/01/25 21:28:23
@@ -669,6 +669,8 @@ struct lang_identifier
 #define DECL_MAX_STACK(DECL) (DECL_LANG_SPECIFIC(DECL)->max_stack)
 /* Number of local variable slots needed for the arguments of this function. */
 #define DECL_ARG_SLOT_COUNT(DECL) (DECL_LANG_SPECIFIC(DECL)->arg_slot_count)
+/* Information on declaration location */
+#define DECL_FUNCTION_WFL(DECL)  (DECL_LANG_SPECIFIC(DECL)->wfl)
 /* List of checked thrown exceptions, as specified with the `throws'
    keyword */
 #define DECL_FUNCTION_THROWS(DECL) (DECL_LANG_SPECIFIC(DECL)->throws_list)
@@ -835,6 +837,7 @@ struct lang_decl
   long localvariables_offset;
   int arg_slots;
   int max_locals, max_stack, arg_slot_count;
+  tree wfl;			/* Information on the original location */
   tree throws_list;		/* Exception specified by `throws' */
   tree function_decl_body;	/* Hold all function's statements */
   tree called_constructor;	/* When decl is a constructor, the
@@ -1037,7 +1040,6 @@ extern char *print_int_node PARAMS ((tre
 extern void parse_error_context PARAMS ((tree cl, const char *, ...))
   ATTRIBUTE_PRINTF_2;
 extern tree build_primtype_type_ref PARAMS ((const char *));
-extern tree java_get_real_method_name PARAMS ((tree));
 extern void finish_class PARAMS ((void));
 extern void java_layout_seen_class_methods PARAMS ((void));
 extern void check_for_initialization PARAMS ((tree));
Index: mangle.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/mangle.c,v
retrieving revision 1.11
diff -u -p -r1.11 mangle.c
--- mangle.c	2001/01/15 08:01:22	1.11
+++ mangle.c	2001/01/25 21:28:24
@@ -152,11 +152,6 @@ mangle_method_decl (mdecl)
   /* Mangle the name of the type that contains mdecl */
   mangle_record_type (DECL_CONTEXT (mdecl), /* from_pointer = */ 0);
 
-  /* Before working on the method name, get to it. It might be burried
-     in a WFL. */
-  if (TREE_CODE (method_name) == EXPR_WITH_FILE_LOCATION)
-    method_name = java_get_real_method_name (mdecl);
-
   /* Mangle the function name. There three cases
        - mdecl is java.lang.Object.Object(), use `C2' for its name
          (denotes a base object constructor.)
Index: parse.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.h,v
retrieving revision 1.62
diff -u -p -r1.62 parse.h
--- parse.h	2000/11/22 05:25:15	1.62
+++ parse.h	2001/01/25 21:28:27
@@ -125,10 +125,6 @@ extern tree stabilize_reference PARAMS (
 #define GET_REAL_TYPE(TYPE) 					\
   (TREE_CODE (TYPE) == TREE_LIST ? TREE_PURPOSE (TYPE) : TYPE)
 
-#define GET_METHOD_NAME(METHOD)					\
-  (TREE_CODE (DECL_NAME (METHOD)) == EXPR_WITH_FILE_LOCATION ?	\
-   EXPR_WFL_NODE (DECL_NAME (METHOD)) : DECL_NAME (METHOD))
-
 /* Get TYPE name string, regardless whether TYPE is a class or an
    array. */
 #define GET_TYPE_NAME(TYPE)				\
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.246
diff -u -p -r1.246 parse.y
--- parse.y	2001/01/24 08:08:36	1.246
+++ parse.y	2001/01/25 21:29:02
@@ -249,7 +249,6 @@ static tree create_artificial_method PAR
 static void start_artificial_method_body PARAMS ((tree));
 static void end_artificial_method_body PARAMS ((tree));
 static int check_method_redefinition PARAMS ((tree, tree));
-static int reset_method_name PARAMS ((tree));
 static int check_method_types_complete PARAMS ((tree));
 static void java_check_regular_methods PARAMS ((tree));
 static void java_check_abstract_methods PARAMS ((tree));
@@ -4513,6 +4512,9 @@ method_header (flags, type, mdecl, throw
       DECL_FUNCTION_THROWS (meth) = throws;
     }
 
+  if (TREE_TYPE (GET_CPC ()) != object_type_node)
+    DECL_FUNCTION_WFL (meth) = id;
+
   /* Set the flag if we correctly processed a constructor */
   if (constructor_ok)
     {
@@ -4715,15 +4717,13 @@ check_abstract_method_header (meth)
      tree meth;
 {
   int flags = get_access_flags_from_decl (meth);
-  /* DECL_NAME might still be a WFL node */
-  tree name = GET_METHOD_NAME (meth);
 
   OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (ABSTRACT_TK), flags,
 			      ACC_ABSTRACT, "abstract method",
-			      IDENTIFIER_POINTER (name));
+			      IDENTIFIER_POINTER (DECL_NAME (meth)));
   OBSOLETE_MODIFIER_WARNING2 (MODIFIER_WFL (PUBLIC_TK), flags, 
 			      ACC_PUBLIC, "abstract method",
-			      IDENTIFIER_POINTER (name));
+			      IDENTIFIER_POINTER (DECL_NAME (meth)));
 
   check_modifiers ("Illegal modifier `%s' for interface method",
 		  flags, INTERFACE_METHOD_MODIFIERS);
@@ -5809,50 +5809,6 @@ get_printable_method_name (decl)
   return to_return;
 }
 
-/* Reinstall the proper DECL_NAME on METHOD. Return 0 if the method
-   nevertheless needs to be verfied, 1 otherwise.  */
-
-static int
-reset_method_name (method)
-     tree method;
-{
-  if (!DECL_CLINIT_P (method) && !DECL_FINIT_P (method))
-    {
-      /* NAME is just the plain name when Object is being defined */
-      if (DECL_CONTEXT (method) != object_type_node)
-	DECL_NAME (method) = (DECL_CONSTRUCTOR_P (method) ? 
-			      init_identifier_node : GET_METHOD_NAME (method));
-      return 0;
-    }
-  else 
-    return 1;
-}
-
-/* Return the name of METHOD_DECL, when DECL_NAME is a WFL */
-
-tree
-java_get_real_method_name (method_decl)
-     tree method_decl;
-{
-  tree method_name = DECL_NAME (method_decl);
-  if (DECL_CONSTRUCTOR_P (method_decl))
-    return init_identifier_node;
-
-  /* Explain here why METHOD_DECL doesn't have the DECL_CONSTRUCTUR_P
-     and still can be a constructor. FIXME */
-
-  /* Don't confuse method only bearing the name of their class as
-     constructors */
-  else if (!CLASS_FROM_SOURCE_P (DECL_CONTEXT (method_decl))
-	   && ctxp
-	   && GET_CPC_UN () == EXPR_WFL_NODE (method_name)
-	   && get_access_flags_from_decl (method_decl) <= ACC_PROTECTED
-	   && TREE_TYPE (TREE_TYPE (method_decl)) == void_type_node)
-    return init_identifier_node;
-  else
-    return EXPR_WFL_NODE (method_name);
-}
-
 /* Track method being redefined inside the same class. As a side
    effect, set DECL_NAME to an IDENTIFIER (prior entering this
    function it's a FWL, so we can track errors more accurately.)  */
@@ -5861,28 +5817,23 @@ static int
 check_method_redefinition (class, method)
      tree class, method;
 {
-  tree redef, name;
-  tree cl = DECL_NAME (method);
-  tree sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
-  /* decl name of artificial <clinit> and finit$ doesn't need to be
-     fixed and checked */
-
-  /* Reset the method name before running the check. If it returns 1,
-     the method doesn't need to be verified with respect to method
-     redeclaration and we return 0 */
-  if (reset_method_name (method))
+  tree redef, sig;
+
+  /* There's no need to verify <clinit> and finit$ */
+  if (DECL_CLINIT_P (method) || DECL_FINIT_P (method))
     return 0;
 
-  name = DECL_NAME (method);
+  sig = TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (method));
   for (redef = TYPE_METHODS (class); redef; redef = TREE_CHAIN (redef))
     {
       if (redef == method)
 	break;
-      if (DECL_NAME (redef) == name 
-	  && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef)))
+      if (DECL_NAME (redef) == DECL_NAME (method)
+	  && sig == TYPE_ARGUMENT_SIGNATURE (TREE_TYPE (redef))
+	  && !DECL_ARTIFICIAL (method))
 	{
 	  parse_error_context 
-	    (cl, "Duplicate %s declaration `%s'",
+	    (DECL_FUNCTION_WFL (method), "Duplicate %s declaration `%s'",
 	     (DECL_CONSTRUCTOR_P (redef) ? "constructor" : "method"),
 	     get_printable_method_name (redef));
 	  return 1;
@@ -6078,7 +6029,7 @@ java_check_regular_methods (class_decl)
   int saw_constructor = ANONYMOUS_CLASS_P (TREE_TYPE (class_decl));
   tree method;
   tree class = CLASS_TO_HANDLE_TYPE (TREE_TYPE (class_decl));
-  tree saved_found_wfl = NULL_TREE, found = NULL_TREE;
+  tree found = NULL_TREE;
   tree mthrows;
 
   /* It is not necessary to check methods defined in java.lang.Object */
@@ -6092,17 +6043,9 @@ java_check_regular_methods (class_decl)
   for (method = TYPE_METHODS (class); method; method = TREE_CHAIN (method))
     {
       tree sig;
-      tree method_wfl = DECL_NAME (method);
+      tree method_wfl = DECL_FUNCTION_WFL (method);
       int aflags;
 
-      /* If we previously found something and its name was saved,
-         reinstall it now */
-      if (found && saved_found_wfl)
-	{
-	  DECL_NAME (found) = saved_found_wfl;
-	  saved_found_wfl = NULL_TREE;
-	}
-
       /* Check for redefinitions */
       if (check_method_redefinition (class, method))
 	continue;
@@ -6150,11 +6093,6 @@ java_check_regular_methods (class_decl)
 	  continue;
 	}
 
-      /* If found wasn't verified, it's DECL_NAME won't be set properly. 
-	 We set it temporarily for the sake of the error report. */
-      saved_found_wfl = DECL_NAME (found);
-      reset_method_name (found);
-
       /* If `found' is declared in an interface, make sure the
 	 modifier matches. */
       if (CLASS_INTERFACE (TYPE_NAME (DECL_CONTEXT (found))) 
@@ -6245,13 +6183,6 @@ java_check_regular_methods (class_decl)
       /* Inheriting multiple methods with the same signature. FIXME */
     }
   
-  /* Don't forget eventual pending found and saved_found_wfl. Take
-     into account that we might have exited because we saw an
-     artificial method as the last entry. */
-
-  if (found && !DECL_ARTIFICIAL (found) && saved_found_wfl)
-    DECL_NAME (found) = saved_found_wfl;
-
   if (!TYPE_NVIRTUALS (class))
     TYPE_METHODS (class) = nreverse (TYPE_METHODS (class));
 
@@ -6311,8 +6242,6 @@ java_check_abstract_methods (interface_d
 
   for (method = TYPE_METHODS (interface); method; method = TREE_CHAIN (method))
     {
-      tree method_wfl = DECL_NAME (method);
-
       /* 2- Check for double definition inside the defining interface */
       if (check_method_redefinition (interface, method))
 	continue;
@@ -6323,17 +6252,14 @@ java_check_abstract_methods (interface_d
       if (found)
 	{
 	  char *t;
-	  tree saved_found_wfl = DECL_NAME (found);
-	  reset_method_name (found);
 	  t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
 	  parse_error_context 
-	    (method_wfl,
+	    (DECL_FUNCTION_WFL (found),
 	     "Method `%s' was defined with return type `%s' in class `%s'",
 	     lang_printable_name (found, 0), t,
 	     IDENTIFIER_POINTER 
 	       (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
 	  free (t);
-	  DECL_NAME (found) = saved_found_wfl;
 	  continue;
 	}
     }
@@ -6357,8 +6283,6 @@ java_check_abstract_methods (interface_d
 						 sub_interface_method);
 	  if (found && (found != sub_interface_method))
 	    {
-	      tree saved_found_wfl = DECL_NAME (found);
-	      reset_method_name (found);
 	      parse_error_context 
 		(lookup_cl (sub_interface_method),
 		 "Interface `%s' inherits method `%s' from interface `%s'. This method is redefined with a different return type in interface `%s'",
@@ -6369,7 +6293,6 @@ java_check_abstract_methods (interface_d
 			       (DECL_CONTEXT (sub_interface_method)))),
 		 IDENTIFIER_POINTER 
 	           (DECL_NAME (TYPE_NAME (DECL_CONTEXT (found)))));
-	      DECL_NAME (found) = saved_found_wfl;
 	    }
 	}
     }
@@ -8681,7 +8604,6 @@ java_expand_classes ()
 		  if (DECL_CONSTRUCTOR_P (d))
 		    {
 		      restore_line_number_status (1);
-		      reset_method_name (d);
 		      java_complete_expand_method (d);
 		      restore_line_number_status (0);
 		      break;	/* We now there are no other ones */
@@ -10605,7 +10527,7 @@ search_applicable_methods_list (lc, meth
       if (lc && !DECL_CONSTRUCTOR_P (method))
 	continue;
       else if (!lc && (DECL_CONSTRUCTOR_P (method) 
-		       || (GET_METHOD_NAME (method) != name)))
+		       || (DECL_NAME (method) != name)))
 	continue;
 
       if (argument_types_convertible (method, arglist))
Index: typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/typeck.c,v
retrieving revision 1.33
diff -u -p -r1.33 typeck.c
--- typeck.c	2000/10/13 06:26:46	1.33
+++ typeck.c	2001/01/25 21:29:05
@@ -812,11 +812,8 @@ lookup_do (searched_class, searched_inte
               method != NULL_TREE;  method = TREE_CHAIN (method))
            {
              tree method_sig = (*signature_builder) (TREE_TYPE (method));
-	     tree name = DECL_NAME (method);
 
-	     if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
-		  EXPR_WFL_NODE (name) : name) == method_name
-		 && method_sig == signature)
+	     if (DECL_NAME (method) == method_name && method_sig == signature)
                return method;
            }
 
@@ -839,9 +836,7 @@ lookup_do (searched_class, searched_inte
 	  tree method_sig = (*signature_builder) (TREE_TYPE (method));
 	  tree name = DECL_NAME (method);
 
-	  if ((TREE_CODE (name) == EXPR_WITH_FILE_LOCATION ?
-	       EXPR_WFL_NODE (name) : name) == method_name
-	      && method_sig == signature)
+	  if (DECL_NAME (method) == method_name && method_sig == signature)
 	    return method;
 	}
       searched_class = CLASSTYPE_SUPER (searched_class);


More information about the Java-patches mailing list