This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java 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]

[Patch] java PR 12734


Hi,

A patch that fixes PR 12734 and adds test cases is below.

It cleans up qualify_ambiguous_name in java/parse.y a bit.  It could be
cleaned up even more, but I stopped when I could no longer get it to
cause ICEs.

There are still a couple of ICEs on illegal field access due to problems
elsewhere.  I'll log those as separate bugs.

Ralph.

PS.  My signed copyright assignment forms are in the mail back to FSF.

2003-10-01  Ralph Loader <suckfish@ihug.co.nz>

	PR java/12734:
	* parse.y (qualify_ambiguous_name): Remove lots of broken
	field access processing - there's no need to do that here,
	because we have resolve_field_access.  Remove
	RESOLVE_EXPRESSION_NAME_P as it isn't used anywhere else.

	* java-tree.h: Remove RESOLVE_EXPRESSION_NAME_P as it isn't
        used.

	* PR12734.java: New file.
	* PR12734_B.java: New file.

Index: gcc/java/java-tree.h
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/java-tree.h,v
retrieving revision 1.184
diff -u -u -r1.184 java-tree.h
--- gcc/java/java-tree.h	28 Sep 2003 13:23:12 -0000	1.184
+++ gcc/java/java-tree.h	30 Sep 2003 19:46:36 -0000
@@ -44,7 +44,6 @@
 
 /* Usage of TREE_LANG_FLAG_?:
    0: IS_A_SINGLE_IMPORT_CLASSFILE_NAME_P (in IDENTIFIER_NODE)
-      RESOLVE_EXPRESSION_NAME_P (in EXPR_WITH_FILE_LOCATION)
       FOR_LOOP_P (in LOOP_EXPR)
       SUPPRESS_UNREACHABLE_ERROR (for other _EXPR nodes)
       ANONYMOUS_CLASS_P (in RECORD_TYPE)
@@ -1524,9 +1523,6 @@
 /* True if TYPE (a TREE_TYPE denoting a class type) was found to
    feature a finalizer method. */
 #define HAS_FINALIZER_P(EXPR) TREE_LANG_FLAG_3 (EXPR)
-
-/* True if EXPR (a WFL in that case) resolves into an expression name */
-#define RESOLVE_EXPRESSION_NAME_P(WFL) TREE_LANG_FLAG_0 (WFL)
 
 /* True if EXPR (a LOOP_EXPR in that case) is part of a for statement */
 #define FOR_LOOP_P(EXPR) TREE_LANG_FLAG_0 (EXPR)
Index: gcc/java/parse.y
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.448
diff -u -u -r1.448 parse.y
--- gcc/java/parse.y	28 Sep 2003 22:18:33 -0000	1.448
+++ gcc/java/parse.y	30 Sep 2003 19:47:39 -0000
@@ -9796,7 +9796,6 @@
 		  list = TREE_CHAIN (q);
 		  while (list)
 		    {
-		      RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (list)) = 1;
 		      RESOLVE_PACKAGE_NAME_P (QUAL_WFL (list)) = 0;
 		      list = TREE_CHAIN (list);
 		    }
@@ -11274,12 +11273,22 @@
 
 /* Qualification routines */
 
+/* At it's heart, this function is doing something nice and simple.
+   Given a name x.y.z, look up x locally.  If it's found, save the
+   decl.  If it's not found, mark the name as RESOLVE_PACKAGE_NAME_P,
+   so that we try and load the appropriate classes.
+
+   Unfortunately, our callers make life hard for us.  Instead of
+   passing us the name, they pass us a random expression and expect us
+   to guess what name they mean.  There are 150 odd lines of dodgy
+   heuristics below to do that guessing, and these may or may not get
+   this correct.  When we get it wrong, we tend to incorrectly mark
+   things RESOLVE_PACKAGE_NAME_P, causing an ICE later on.  */
 static void
 qualify_ambiguous_name (tree id)
 {
-  tree qual, qual_wfl, name = NULL_TREE, decl, ptr_type = NULL_TREE,
-    saved_current_class;
-  int again, super_found = 0, this_found = 0, new_array_found = 0;
+  tree qual, qual_wfl, name = NULL_TREE, decl;
+  int again;
   int code;
 
   /* We first qualify the first element, then derive qualification of
@@ -11288,7 +11297,6 @@
      QUAL_RESOLUTION of the qual element being examined. We need to
      save the current_class since the use of SUPER might change the
      its value. */
-  saved_current_class = current_class;
   qual = EXPR_WFL_QUALIFICATION (id);
   do {
 
@@ -11310,11 +11318,6 @@
 	    qual_wfl = QUAL_WFL (qual);
 	  }
 	break;
-      case NEW_ARRAY_EXPR:
-      case NEW_ANONYMOUS_ARRAY_EXPR:
-	qual = TREE_CHAIN (qual);
-	again = new_array_found = 1;
-	continue;
       case CONVERT_EXPR:
 	break;
       case NEW_CLASS_EXPR:
@@ -11324,20 +11327,16 @@
 	while (TREE_CODE (qual_wfl) == ARRAY_REF)
 	  qual_wfl = TREE_OPERAND (qual_wfl, 0);
 	break;
+      case NEW_ARRAY_EXPR:
+      case NEW_ANONYMOUS_ARRAY_EXPR:
       case STRING_CST:
-	qual = TREE_CHAIN (qual);
-	qual_wfl = QUAL_WFL (qual);
-	break;
       case CLASS_LITERAL:
-	qual = TREE_CHAIN (qual);
-	qual_wfl = QUAL_WFL (qual);
-      break;
+	return;		/* Field access processing will handle it.  */
       default:
 	/* Fix for -Wall. Just break doing nothing */
 	break;
       }
 
-    ptr_type = current_class;
     again = 0;
     code = TREE_CODE (qual_wfl);
 
@@ -11368,11 +11367,9 @@
 
     else if (code == STRING_CST || code == CONDITIONAL_EXPR
 	     || code == PLUS_EXPR)
-      {
-	qual = TREE_CHAIN (qual);
-	qual_wfl = QUAL_WFL (qual);
-	again = 1;
-      }
+      /* Let field access processing do its job.  */
+      return;
+
     else
       {
 	name = EXPR_WFL_NODE (qual_wfl);
@@ -11383,70 +11380,27 @@
 	  }
       }
 
-    /* If we have a THIS (from a primary), we set the context accordingly */
-    if (name == this_identifier_node)
-      {
-	/* This isn't really elegant. One more added irregularity
-	   before I start using COMPONENT_REF (hopefully very soon.)  */
-	if (TREE_CODE (TREE_PURPOSE (qual)) == ARRAY_REF
-	    && TREE_CODE (TREE_OPERAND (TREE_PURPOSE (qual), 0)) ==
-	       EXPR_WITH_FILE_LOCATION
-	    && EXPR_WFL_NODE (TREE_OPERAND (TREE_PURPOSE (qual), 0)) ==
-	       this_identifier_node)
-	    {
-	      qual = TREE_OPERAND (TREE_PURPOSE (qual), 0);
-	      qual = EXPR_WFL_QUALIFICATION (qual);
-	    }
-	qual = TREE_CHAIN (qual);
-	qual_wfl = QUAL_WFL (qual);
-	if (TREE_CODE (qual_wfl) == CALL_EXPR)
-	  again = 1;
-	else if (TREE_CODE (qual_wfl) == EXPR_WITH_FILE_LOCATION)
-	  name = EXPR_WFL_NODE (qual_wfl);
-	else if (TREE_CODE (qual_wfl) == NEW_CLASS_EXPR)
-	  name = TREE_OPERAND (qual_wfl, 0);
-	this_found = 1;
-      }
-    /* If we have a SUPER, we set the context accordingly */
-    if (name == super_identifier_node)
-      {
-	current_class = CLASSTYPE_SUPER (ptr_type);
-	/* Check that there is such a thing as a super class. If not,
-	   return.  The error will be caught later on, during the
-	   resolution */
-	if (!current_class)
-	  {
-	    current_class = saved_current_class;
-	    return;
-	  }
-	qual = TREE_CHAIN (qual);
-	/* Do one more interation to set things up */
-	super_found = again = 1;
-      }
+    /* If we have a this or super, then field access processing does
+       the right thing : there is nothing for us to do.  */
+    if (name == this_identifier_node ||
+	name == super_identifier_node)
+      return;
+
   } while (again);
 
   /* If name appears within the scope of a local variable declaration
      or parameter declaration, then it is an expression name. We don't
      carry this test out if we're in the context of the use of SUPER
      or THIS */
-  if (!this_found && !super_found
-      && TREE_CODE (name) != STRING_CST && TREE_CODE (name) != INTEGER_CST
+  if (TREE_CODE (name) != STRING_CST && TREE_CODE (name) != INTEGER_CST
       && (decl = IDENTIFIER_LOCAL_VALUE (name)))
-    {
-      RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
-      QUAL_RESOLUTION (qual) = decl;
-    }
+    QUAL_RESOLUTION (qual) = decl;
 
   /* If within the class/interface NAME was found to be used there
      exists a (possibly inherited) field named NAME, then this is an
-     expression name. If we saw a NEW_ARRAY_EXPR before and want to
-     address length, it is OK. */
-  else if ((decl = lookup_field_wrapper (ptr_type, name))
-	   || name == length_identifier_node)
-    {
-      RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
-      QUAL_RESOLUTION (qual) = (new_array_found ? NULL_TREE : decl);
-    }
+     expression name.  */
+  else if ((decl = lookup_field_wrapper (current_class, name)))
+    QUAL_RESOLUTION (qual) = decl;
 
   /* We reclassify NAME as yielding to a type name resolution if:
      - NAME is a class/interface declared within the compilation
@@ -11458,10 +11412,9 @@
      of the compilation unit containing NAME.
      - NAME is actually a STRING_CST.
      This can't happen if the expression was qualified by `this.' */
-  else if (! this_found &&
-	   (TREE_CODE (name) == STRING_CST ||
-	    TREE_CODE (name) == INTEGER_CST ||
-	    (decl = resolve_and_layout (name, NULL_TREE))))
+  else if (TREE_CODE (name) == STRING_CST ||
+	   TREE_CODE (name) == INTEGER_CST ||
+	   (decl = resolve_and_layout (name, NULL_TREE)))
     {
       RESOLVE_TYPE_NAME_P (qual_wfl) = 1;
       QUAL_RESOLUTION (qual) = decl;
@@ -11472,7 +11425,7 @@
 	   || TREE_CODE (QUAL_WFL (qual)) == ARRAY_REF
 	   || TREE_CODE (QUAL_WFL (qual)) == CONVERT_EXPR
 	   || TREE_CODE (QUAL_WFL (qual)) == MODIFY_EXPR)
-    RESOLVE_EXPRESSION_NAME_P (qual_wfl) = 1;
+    return;			/* Field access.  */
 
   /* Check here that NAME isn't declared by more than one
      type-import-on-demand declaration of the compilation unit
@@ -11489,21 +11442,14 @@
     {
       if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
 	RESOLVE_PACKAGE_NAME_P (QUAL_WFL (qual)) = 1;
-      else
-	RESOLVE_EXPRESSION_NAME_P (QUAL_WFL (qual)) = 1;
     }
 
   /* Store the global qualification for the ambiguous part of ID back
      into ID fields */
-  if (RESOLVE_EXPRESSION_NAME_P (qual_wfl))
-    RESOLVE_EXPRESSION_NAME_P (id) = 1;
-  else if (RESOLVE_TYPE_NAME_P (qual_wfl))
+  if (RESOLVE_TYPE_NAME_P (qual_wfl))
     RESOLVE_TYPE_NAME_P (id) = 1;
   else if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
     RESOLVE_PACKAGE_NAME_P (id) = 1;
-
-  /* Restore the current class */
-  current_class = saved_current_class;
 }
 
 static int
--- /dev/null	2003-09-16 01:40:47.000000000 +1200
+++ libjava/testsuite/libjava.compile/PR12734.java	2003-09-29 13:31:58.000000000 +1200
@@ -0,0 +1,7 @@
+class PR12734 {
+    Object Foo()
+    {
+	return "".CASE_INSENSITIVE_ORDER;
+    }
+}
+
--- /dev/null	2003-09-16 01:40:47.000000000 +1200
+++ libjava/testsuite/libjava.compile/PR12734_B.java	2003-10-01 07:47:50.907153042 +1200
@@ -0,0 +1,15 @@
+/* Special casing access to array.length while analysing syntax is
+   evil.  Especially when it means we can't cope with a type called
+   length.  */
+class PR12734_B
+{
+    class length
+    {
+	static final int i = 2;
+    }
+
+    int foo()
+    {
+	return length.i;
+    }
+}



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