Commit 2f418289 by Bryce McKinlay Committed by Bryce McKinlay

re PR java/5993 (crashes on Hello World)

	Fix for PR java/5993:
	* 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.

From-SVN: r51497
parent 96adcacb
2002-03-28 Bryce McKinlay <bryce@waitaki.otago.ac.nz>
Fix for PR java/5993:
* 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.
2002-03-27 Tom Tromey <tromey@redhat.com> 2002-03-27 Tom Tromey <tromey@redhat.com>
* expr.c (expand_invoke): Don't generate null pointer check if * expr.c (expand_invoke): Don't generate null pointer check if
......
...@@ -104,7 +104,7 @@ static void find_in_imports PARAMS ((tree, tree)); ...@@ -104,7 +104,7 @@ static void find_in_imports PARAMS ((tree, tree));
static void check_inner_class_access PARAMS ((tree, tree, tree)); static void check_inner_class_access PARAMS ((tree, tree, tree));
static int check_pkg_class_access PARAMS ((tree, tree, bool)); static int check_pkg_class_access PARAMS ((tree, tree, bool));
static void register_package PARAMS ((tree)); 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 lookup_package_type PARAMS ((const char *, int));
static tree resolve_class PARAMS ((tree, tree, tree, tree)); static tree resolve_class PARAMS ((tree, tree, tree, tree));
static void declare_local_variables PARAMS ((int, tree, tree)); static void declare_local_variables PARAMS ((int, tree, tree));
...@@ -7031,49 +7031,31 @@ register_package (name) ...@@ -7031,49 +7031,31 @@ register_package (name)
} }
static tree static tree
resolve_package (pkg, next) resolve_package (pkg, next, type_name)
tree pkg, *next; tree pkg, *next, *type_name;
{ {
tree current, acc; tree current, decl;
tree type_name = NULL_TREE; *type_name = NULL_TREE;
const char *name = IDENTIFIER_POINTER (EXPR_WFL_NODE (pkg));
/* The trick is to determine when the package name stops and were /* The trick is to determine when the package name stops and were
the name of something contained in the package starts. Then we the name of something contained in the package starts. Then we
return a fully qualified name of what we want to get. */ 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); *next = EXPR_WFL_QUALIFICATION (pkg);
/* Try to progressively construct a type name */ /* Try to progressively construct a type name */
if (TREE_CODE (pkg) == EXPR_WITH_FILE_LOCATION) 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)) current; current = TREE_CHAIN (current))
{ {
/* If we don't have what we're expecting, exit now. TYPE_NAME /* If we don't have what we're expecting, exit now. TYPE_NAME
will be null and the error caught later. */ will be null and the error caught later. */
if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION) if (TREE_CODE (QUAL_WFL (current)) != EXPR_WITH_FILE_LOCATION)
break; break;
acc = merge_qualified_name (acc, EXPR_WFL_NODE (QUAL_WFL (current))); *type_name =
if ((type_name = resolve_no_layout (acc, NULL_TREE))) 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 /* resolve_package should be used in a loop, hence we
point at this one to naturally process the next one at point at this one to naturally process the next one at
the next iteration. */ the next iteration. */
...@@ -7081,7 +7063,7 @@ resolve_package (pkg, next) ...@@ -7081,7 +7063,7 @@ resolve_package (pkg, next)
break; break;
} }
} }
return type_name; return decl;
} }
static tree static tree
...@@ -9677,11 +9659,12 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found) ...@@ -9677,11 +9659,12 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
assume a variable/class name was meant. */ assume a variable/class name was meant. */
if (RESOLVE_PACKAGE_NAME_P (qual_wfl)) if (RESOLVE_PACKAGE_NAME_P (qual_wfl))
{ {
tree name = resolve_package (wfl, &q); tree name;
if (name) if ((decl = resolve_package (wfl, &q, &name)))
{ {
tree list; 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 /* We want to be absolutely sure that the class is laid
out. We're going to search something inside it. */ out. We're going to search something inside it. */
*type_found = type = TREE_TYPE (decl); *type_found = type = TREE_TYPE (decl);
...@@ -9711,7 +9694,7 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found) ...@@ -9711,7 +9694,7 @@ resolve_qualified_expression_name (wfl, found_decl, where_found, type_found)
else else
parse_error_context parse_error_context
(qual_wfl, "Undefined variable or class name: `%s'", (qual_wfl, "Undefined variable or class name: `%s'",
IDENTIFIER_POINTER (EXPR_WFL_NODE (qual_wfl))); IDENTIFIER_POINTER (name));
return 1; return 1;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment