This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Java: Fix for PR 5993
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: java-patches at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Tue, 26 Mar 2002 23:07:25 +1200
- Subject: Java: Fix for PR 5993
This patch fixes PR 5993. It also improves error messages in cases where
a class name can't be found. eg previously with something like:
class Foo
{
int a()
{
return java.util.Boo.x;
}
}
Foo.java: In class `Foo':
Foo.java: In method `Foo.a()':
Foo.java:5: Undefined variable or class name: `java'.
return java.util.Boo.x;
^
Now we get:
Foo.java: In class `Foo':
Foo.java: In method `Foo.a()':
Foo.java:5: Undefined variable or class name: `java.util.Boo.x'.
return java.util.Boo.x;
^
1 error
OK to commit?
regards
Bryce.
2002-03-26 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
* parse.y (resolve_package): Return the decl if resolution was
successful. Don't special case "java.lang" and "java.lang.reflect"
packages. Set type_name to the merged identifier.
(resolved_qualified_expression_name): Print error using "name" if
resolve_package returns NULL_TREE.
Fix for PR java/5993.
Index: parse.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse.y,v
retrieving revision 1.363
diff -u -r1.363 parse.y
--- parse.y 2002/03/25 19:23:37 1.363
+++ parse.y 2002/03/26 10:58:07
@@ -104,7 +104,7 @@
static void check_inner_class_access PARAMS ((tree, tree, tree));
static int check_pkg_class_access PARAMS ((tree, tree, bool));
static void register_package PARAMS ((tree));
-static tree resolve_package PARAMS ((tree, tree *));
+static tree resolve_package PARAMS ((tree, tree *, tree *));
static tree lookup_package_type PARAMS ((const char *, int));
static tree resolve_class PARAMS ((tree, tree, tree, tree));
static void declare_local_variables PARAMS ((int, tree, tree));
@@ -7024,49 +7024,31 @@
}
static tree
-resolve_package (pkg, next)
- tree pkg, *next;
+resolve_package (pkg, next, type_name)
+ tree pkg, *next, *type_name;
{
- tree current, acc;
- tree type_name = NULL_TREE;
- const char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
+ tree current, decl;
+ *type_name = NULL_TREE;
/* The trick is to determine when the package name stops and were
the name of something contained in the package starts. Then we
return a fully qualified name of what we want to get. */
- /* Do a quick search on well known package names */
- if (!strncmp (name, "java.lang.reflect", 17))
- {
- *next =
- TREE_CHAIN (TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg))));
- type_name = lookup_package_type (name, 17);
- }
- else if (!strncmp (name, "java.lang", 9))
- {
- *next = TREE_CHAIN (TREE_CHAIN (EXPR_WFL_QUALIFICATION (pkg)));
- type_name = lookup_package_type (name, 9);
- }
-
- /* If we found something here, return */
- if (type_name)
- return type_name;
-
*next = EXPR_WFL_QUALIFICATION (pkg);
/* Try to progressively construct a type name */
if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION)
- for (acc = NULL_TREE, current = EXPR_WFL_QUALIFICATION (pkg);
+ for (current = EXPR_WFL_QUALIFICATION (pkg);
current; current = TREE_CHAIN (current))
{
/* If we don't have what we're expecting, exit now. TYPE_NAME
will be null and the error caught later. */
if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION)
break;
- acc = merge_qualified_name (acc, EXPR_WFL_NODE (QUAL_WFL (current)));
- if ((type_name = resolve_no_layout (acc, NULL_TREE)))
+ *type_name =
+ merge_qualified_name (*type_name, EXPR_WFL_NODE (QUAL_WFL (current)));
+ if ((decl = resolve_no_layout (*type_name, NULL_TREE)))
{
- type_name = acc;
/* resolve_package should be used in a loop, hence we
point at this one to naturally process the next one at
the next iteration. */
@@ -7074,7 +7056,7 @@
break;
}
}
- return type_name;
+ return decl;
}
static tree
@@ -9670,11 +9652,12 @@
assume a variable/class name was meant. */
if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
{
- tree name = resolve_package (wfl, &q);
- if (name)
+ tree name;
+ if ((decl = resolve_package (wfl, &q, &name)))
{
tree list;
- *where_found = decl = resolve_no_layout (name, qual_wfl);
+ *where_found = decl;
+
/* We want to be absolutely sure that the class is laid
out. We're going to search something inside it. */
*type_found = type = TREE_TYPE (decl);
@@ -9704,7 +9687,7 @@
else
parse_error_context
(qual_wfl, "Undefined variable or class name: `%s'",
- IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl)));
+ IDENTIFIER_POINTER (name));
return 1;
}
}