This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
java/4352: jc1 gets confused looking for array of local class
- To: gcc-gnats at gcc dot gnu dot org
- Subject: java/4352: jc1 gets confused looking for array of local class
- From: per at bothner dot com
- Date: Tue, 18 Sep 2001 14:15:14 -0700
>Number: 4352
>Category: java
>Synopsis: jc1 gets confused looking for array of local class
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: rejects-legal
>Submitter-Id: net
>Arrival-Date: Tue Sep 18 14:26:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Per Bothner
>Release: 3.1 20010917 (experimental)
>Organization:
Brainfood
>Environment:
System: Linux eureka.bothner.com 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: /home/bothner/GNU/gcc/configure --enable-threads=posix --prefix=/home/bothner/GNU/install-gcc --enable-languages=c++,java
>Description:
While building Tomcat (using Anthony Green's rhug packaging), jc1
complains incorrectly
./upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java:23: Class `org.apache.tomcat.util.xml.XmlMapper' already defined in upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java:23.
public class XmlMapper
>How-To-Repeat:
Try to build rhug.
make[1]: Entering directory `/home/bothner/Java/rhug/jakarta-tomcat'
source='upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java' object='upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.lo' libtool=yes \
depfile='.deps/upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.Plo' tmpdepfile='.deps/upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.TPlo' \
depmode=gcc3 /bin/sh ../depcomp \
/bin/sh ../libtool --mode=compile gcj --encoding=UTF-8 -fassume-compiled -fCLASSPATH=./upstream/src/share:../jakarta-servletapi/upstream/src/share:../xerces/xerces-1.4.2.jar -O2 -c -o upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.lo `test -f upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java || echo './'`upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java
rm -f upstream/src/share/org/apache/tomcat/util/xml/.libs/XmlMapper.lo
gcj --encoding=UTF-8 -fassume-compiled -fCLASSPATH=./upstream/src/share:../jakarta-servletapi/upstream/src/share:../xerces/xerces-1.4.2.jar -O2 -c upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java -MT upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.lo -MD -MP -MF .deps/upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.TPlo -fPIC -o upstream/src/share/org/apache/tomcat/util/xml/.libs/XmlMapper.lo
./upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java:23: Class `org.apache.tomcat.util.xml.XmlMapper' already defined in upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java:23.
public class XmlMapper
^
./upstream/src/share/org/apache/tomcat/util/xml/XmlMapper.java:49: confused by earlier errors, bailing out
>Fix:
The problem appears to be in resolve_class. It gets passed a
class_type that is:
<pointer_type 0x4031fdec org.apache.tomcat.util.xml.XmlMapper$Rule[] VOID
align 16 symtab 0 alias set -1>
The code handles signature-style array type names:
/* 1- Check to see if we have an array. If true, find what we really
want to resolve */
while (name[0] == '[')
name++;
if (base != name)
{
TYPE_NAME (class_type) = get_identifier (name);
WFL_STRIP_BRACKET (cl, cl);
}
However, it does not handle type names that end in "[]". Note that
for example build_java_array_type creates type names ending in "[]".
I believe this is as it should be.
The following patch seems to fix it. However, note that it doesn't
enulate the old logic of WFL_STRIP_BRACKET. I'm not sure what is
correct.
It might make sense to add an error at the WFL_STRIP_BRACKET so
we can fix the callers that pass signature-style type names.
I think we should be consistent in that the name of a type is
the source-lvele name not the signature, whether the class
comes from .java or .class.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/gcc/gcc/java/parse.y,v
retrieving revision 1.311
diff -u -p -r1.311 parse.y
--- parse.y 2001/09/14 22:58:37 1.311
+++ parse.y 2001/09/18 21:10:43
@@ -5689,6 +5689,22 @@ java_complete_class ()
return;
}
+/* FIXME MOVE TO ../stringpool.c */
+#include "hashtable.h"
+extern tree get_identifier2 (const char *, unsigned int);
+tree
+get_identifier2 (text, length)
+ const char *text;
+ unsigned int length;
+{
+ hashnode ht_node = ht_lookup (ident_hash,
+ (const unsigned char *) text,
+ length, HT_ALLOC);
+
+ /* ht_node can't be NULL here. */
+ return HT_IDENT_TO_GCC_IDENT (ht_node);
+}
+
/* Resolve class CLASS_TYPE. Handle the case of trying to resolve an
array. */
@@ -5696,7 +5712,10 @@ static tree
resolve_class (enclosing, class_type, decl, cl)
tree enclosing, class_type, decl, cl;
{
- const char *name = IDENTIFIER_POINTER (TYPE_NAME (class_type));
+ tree tname = TYPE_NAME (class_type);
+ const char *name = IDENTIFIER_POINTER (tname);
+ int arrays = 0;
+ int namelen = IDENTIFIER_LENGTH (tname);
const char *base = name;
tree resolved_type = TREE_TYPE (class_type);
tree resolved_type_decl;
@@ -5716,6 +5735,31 @@ resolve_class (enclosing, class_type, de
/* 1- Check to see if we have an array. If true, find what we really
want to resolve */
+ while (namelen > 2 && name[namelen - 1] == ']')
+ {
+ namelen -= 2;
+ arrays++;
+ }
+ if (arrays > 0)
+ {
+ TYPE_NAME (class_type) = get_identifier2 (name, namelen);
+#if 0
+ if (cl != NULL_TREE && TREE_CODE (cl) == EXPR_WITH_FILE_LOCATION)
+ {
+ tree _node = EXPR_WFL_NODE (cl);
+ const char *_ptr = IDENTIFIER_POINTER (_node);
+ const char *_ref = _ptr;
+ while (_ptr[0] == '[')
+ _ptr++;
+ if (_ref != _ptr)
+ {
+ cl = copy_node (cl);
+ EXPR_WFL_NODE (_new) = get_identifier (_ptr);
+ cl = _new;
+ }
+ }
+#endif
+ }
while (name[0] == '[')
name++;
if (base != name)
>Release-Note:
>Audit-Trail:
>Unformatted: