X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fjava%2Fjcf-parse.c;h=04c04f575cf618e64edf34ccbfde6e4893974e1d;hb=5ffca5d363321b3d47611a3088684a9aa6ff1112;hp=352a0beedcf11824ab32cae7677609b775041a0f;hpb=90483006aa904ba60a0e156f3f03ac466c9e79f3;p=pf3gnuchains%2Fgcc-fork.git
diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c
index 352a0beedcf..04c04f575cf 100644
--- a/gcc/java/jcf-parse.c
+++ b/gcc/java/jcf-parse.c
@@ -1,12 +1,12 @@
/* Parser for Java(TM) .class files.
- Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003
- Free Software Foundation, Inc.
+ Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+ 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
any later version.
GCC is distributed in the hope that it will be useful,
@@ -15,9 +15,8 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GCC; see the file COPYING. If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.
+along with GCC; see the file COPYING3. If not see
+.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
@@ -28,21 +27,21 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "config.h"
#include "system.h"
#include "coretypes.h"
-#include "tm.h"
#include "tree.h"
-#include "real.h"
#include "obstack.h"
#include "flags.h"
#include "java-except.h"
#include "input.h"
+#include "javaop.h"
#include "java-tree.h"
-#include "toplev.h"
+#include "diagnostic-core.h"
#include "parse.h"
#include "ggc.h"
#include "debug.h"
-#include "assert.h"
-#include "tm_p.h"
#include "cgraph.h"
+#include "vecprim.h"
+#include "bitmap.h"
+#include "target.h"
#ifdef HAVE_LOCALE_H
#include
@@ -64,7 +63,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
text = (JCF)->read_ptr; \
save = text[LENGTH]; \
text[LENGTH] = 0; \
- (JCF)->cpool.data[INDEX].t = get_identifier (text); \
+ (JCF)->cpool.data[INDEX].t = get_identifier ((const char *) text); \
text[LENGTH] = save; \
JCF_SKIP (JCF, LENGTH); } while (0)
@@ -72,11 +71,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */
extern struct obstack temporary_obstack;
-/* Set to nonzero value in order to emit class initialization code
- before static field references. */
-extern int always_initialize_class_p;
-
-static GTY(()) tree parse_roots[3];
+static GTY(()) tree parse_roots[2];
/* The FIELD_DECL for the current field. */
#define current_field parse_roots[0]
@@ -84,29 +79,41 @@ static GTY(()) tree parse_roots[3];
/* The METHOD_DECL for the current method. */
#define current_method parse_roots[1]
-/* A list of file names. */
-#define current_file_list parse_roots[2]
+/* Line 0 in current file, if compiling from bytecode. */
+static location_t file_start_location;
/* The Java archive that provides main_class; the main input file. */
static GTY(()) struct JCF * main_jcf;
+/* A list of all the class DECLs seen so far. */
+static GTY(()) VEC(tree,gc) *all_class_list;
+
+/* The number of source files passed to us by -fsource-filename and an
+ array of pointers to each name. Used by find_sourcefile(). */
+static int num_files = 0;
+static char **filenames;
+
static struct ZipFile *localToFile;
+/* A map of byte offsets in the reflection data that are fields which
+ need renumbering. */
+bitmap field_offsets;
+bitmap_obstack bit_obstack;
+
/* Declarations of some functions used here. */
-static void handle_innerclass_attribute (int count, JCF *);
+static void handle_innerclass_attribute (int count, JCF *, int len);
static tree give_name_to_class (JCF *jcf, int index);
static char *compute_class_name (struct ZipDirectory *zdir);
static int classify_zip_file (struct ZipDirectory *zdir);
static void parse_zip_file_entries (void);
static void process_zip_dir (FILE *);
-static void parse_source_file_1 (tree, FILE *);
-static void parse_source_file_2 (void);
-static void parse_source_file_3 (void);
static void parse_class_file (void);
static void handle_deprecated (void);
static void set_source_filename (JCF *, int);
static void jcf_parse (struct JCF*);
static void load_inner_classes (tree);
+static void handle_annotation (JCF *jcf, int level);
+static void java_layout_seen_class_methods (void);
/* Handle "Deprecated" attribute. */
static void
@@ -121,10 +128,185 @@ handle_deprecated (void)
else
{
/* Shouldn't happen. */
- abort ();
+ gcc_unreachable ();
+ }
+}
+
+
+
+/* Reverse a string. */
+static char *
+reverse (const char *s)
+{
+ if (s == NULL)
+ return NULL;
+ else
+ {
+ int len = strlen (s);
+ char *d = XNEWVAR (char, len + 1);
+ const char *sp;
+ char *dp;
+
+ d[len] = 0;
+ for (dp = &d[0], sp = &s[len-1]; sp >= s; dp++, sp--)
+ *dp = *sp;
+
+ return d;
+ }
+}
+
+/* Compare two strings for qsort(). */
+static int
+cmpstringp (const void *p1, const void *p2)
+{
+ /* The arguments to this function are "pointers to
+ pointers to char", but strcmp() arguments are "pointers
+ to char", hence the following cast plus dereference */
+
+ return strcmp(*(const char *const*) p1, *(const char *const*) p2);
+}
+
+/* Create an array of strings, one for each source file that we've
+ seen. fsource_filename can either be the name of a single .java
+ file or a file that contains a list of filenames separated by
+ newlines. */
+void
+java_read_sourcefilenames (const char *fsource_filename)
+{
+ if (fsource_filename
+ && filenames == 0
+ && strlen (fsource_filename) > strlen (".java")
+ && filename_cmp ((fsource_filename
+ + strlen (fsource_filename)
+ - strlen (".java")),
+ ".java") != 0)
+ {
+/* fsource_filename isn't a .java file but a list of filenames
+ separated by newlines */
+ FILE *finput = fopen (fsource_filename, "r");
+ int len = 0;
+ int longest_line = 0;
+
+ gcc_assert (finput);
+
+ /* Find out how many files there are, and how long the filenames are. */
+ while (! feof (finput))
+ {
+ int ch = getc (finput);
+ if (ch == '\n')
+ {
+ num_files++;
+ if (len > longest_line)
+ longest_line = len;
+ len = 0;
+ continue;
+ }
+ if (ch == EOF)
+ break;
+ len++;
+ }
+
+ rewind (finput);
+
+ /* Read the filenames. Put a pointer to each filename into the
+ array FILENAMES. */
+ {
+ char *linebuf = (char *) alloca (longest_line + 1);
+ int i = 0;
+ int charpos;
+
+ filenames = XNEWVEC (char *, num_files);
+
+ charpos = 0;
+ for (;;)
+ {
+ int ch = getc (finput);
+ if (ch == EOF)
+ break;
+ if (ch == '\n')
+ {
+ linebuf[charpos] = 0;
+ gcc_assert (i < num_files);
+ /* ??? Perhaps we should use lrealpath() here. Doing
+ so would tidy up things like /../ but the rest of
+ gcc seems to assume relative pathnames, not
+ absolute pathnames. */
+/* realname = lrealpath (linebuf); */
+ filenames[i++] = reverse (linebuf);
+ charpos = 0;
+ continue;
+ }
+ gcc_assert (charpos < longest_line);
+ linebuf[charpos++] = ch;
+ }
+
+ if (num_files > 1)
+ qsort (filenames, num_files, sizeof (char *), cmpstringp);
+ }
+ fclose (finput);
+ }
+ else
+ {
+ filenames = XNEWVEC (char *, 1);
+ filenames[0] = reverse (fsource_filename);
+ num_files = 1;
+ }
+}
+
+/* Given a relative pathname such as foo/bar.java, attempt to find a
+ longer pathname with the same suffix.
+
+ This is a best guess heuristic; with some weird class hierarchies we
+ may fail to pick the correct source file. For example, if we have
+ the filenames foo/bar.java and also foo/foo/bar.java, we do not
+ have enough information to know which one is the right match for
+ foo/bar.java. */
+
+static const char *
+find_sourcefile (const char *name)
+{
+ int i = 0, j = num_files-1;
+ char *found = NULL;
+
+ if (filenames)
+ {
+ char *revname = reverse (name);
+
+ do
+ {
+ int k = (i+j) / 2;
+ int cmp = strncmp (revname, filenames[k], strlen (revname));
+ if (cmp == 0)
+ {
+ /* OK, so we found one. But is it a unique match? */
+ if ((k > i
+ && strncmp (revname, filenames[k-1], strlen (revname)) == 0)
+ || (k < j
+ && (strncmp (revname, filenames[k+1], strlen (revname))
+ == 0)))
+ ;
+ else
+ found = filenames[k];
+ break;
+ }
+ if (cmp > 0)
+ i = k+1;
+ else
+ j = k-1;
+ }
+ while (i <= j);
+
+ free (revname);
}
+
+ if (found && strlen (found) > strlen (name))
+ return reverse (found);
+ else
+ return name;
}
+
+
/* Handle "SourceFile" attribute. */
static void
@@ -132,28 +314,569 @@ set_source_filename (JCF *jcf, int index)
{
tree sfname_id = get_name_constant (jcf, index);
const char *sfname = IDENTIFIER_POINTER (sfname_id);
- if (input_filename != NULL)
+ const char *old_filename = input_filename;
+ int new_len = IDENTIFIER_LENGTH (sfname_id);
+ if (old_filename != NULL)
{
- int old_len = strlen (input_filename);
- int new_len = IDENTIFIER_LENGTH (sfname_id);
+ int old_len = strlen (old_filename);
/* Use the current input_filename (derived from the class name)
if it has a directory prefix, but otherwise matches sfname. */
if (old_len > new_len
- && strcmp (sfname, input_filename + old_len - new_len) == 0
- && (input_filename[old_len - new_len - 1] == '/'
- || input_filename[old_len - new_len - 1] == '\\'))
+ && filename_cmp (sfname, old_filename + old_len - new_len) == 0
+ && (old_filename[old_len - new_len - 1] == '/'
+ || old_filename[old_len - new_len - 1] == '\\'))
return;
}
- input_filename = sfname;
- DECL_SOURCE_FILE (TYPE_NAME (current_class)) = sfname;
- if (current_class == main_class) main_input_filename = input_filename;
+ if (strchr (sfname, '/') == NULL && strchr (sfname, '\\') == NULL)
+ {
+ const char *class_name
+ = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (current_class)));
+ const char *dot = strrchr (class_name, '.');
+ if (dot != NULL)
+ {
+ /* Length of prefix, not counting final dot. */
+ int i = dot - class_name;
+ /* Concatenate current package prefix with new sfname. */
+ char *buf = XNEWVEC (char, i + new_len + 2); /* Space for '.' and '\0'. */
+ strcpy (buf + i + 1, sfname);
+ /* Copy package from class_name, replacing '.' by DIR_SEPARATOR.
+ Note we start at the end with the final package dot. */
+ for (; i >= 0; i--)
+ {
+ char c = class_name[i];
+ if (c == '.')
+ c = DIR_SEPARATOR;
+ buf[i] = c;
+ }
+ sfname_id = get_identifier (buf);
+ free (buf);
+ sfname = IDENTIFIER_POINTER (sfname_id);
+ }
+ }
+
+ sfname = find_sourcefile (sfname);
+ ORDINARY_MAP_FILE_NAME (LINEMAPS_LAST_ORDINARY_MAP (line_table)) = sfname;
+ if (current_class == main_class) main_input_filename = sfname;
+}
+
+
+
+
+/* Annotation handling.
+
+ The technique we use here is to copy the annotation data directly
+ from the input class file into the output file. We don't decode the
+ data at all, merely rewriting constant indexes whenever we come
+ across them: this is necessary because the constant pool in the
+ output file isn't the same as the constant pool in the input.
+
+ The main advantage of this technique is that the resulting
+ annotation data is pointer-free, so it doesn't have to be relocated
+ at startup time. As a consequence of this, annotations have no
+ performance impact unless they are used. Also, this representation
+ is very dense. */
+
+
+/* Expand TYPE_REFLECTION_DATA by DELTA bytes. Return the address of
+ the start of the newly allocated region. */
+
+static unsigned char*
+annotation_grow (int delta)
+{
+ unsigned char **data = &TYPE_REFLECTION_DATA (current_class);
+ long *datasize = &TYPE_REFLECTION_DATASIZE (current_class);
+ long len = *datasize;
+
+ if (*data == NULL)
+ {
+ *data = XNEWVAR (unsigned char, delta);
+ }
+ else
+ {
+ int newlen = *datasize + delta;
+ if (floor_log2 (newlen) != floor_log2 (*datasize))
+ *data = XRESIZEVAR (unsigned char, *data, 2 << (floor_log2 (newlen)));
+ }
+ *datasize += delta;
+ return *data + len;
+}
+
+/* annotation_rewrite_TYPE. Rewrite various int types at p. Use Java
+ byte order (i.e. big endian.) */
+
+static void
+annotation_rewrite_byte (unsigned int n, unsigned char *p)
+{
+ p[0] = n;
+}
+
+static void
+annotation_rewrite_short (unsigned int n, unsigned char *p)
+{
+ p[0] = n>>8;
+ p[1] = n;
+}
+
+static void
+annotation_rewrite_int (unsigned int n, unsigned char *p)
+{
+ p[0] = n>>24;
+ p[1] = n>>16;
+ p[2] = n>>8;
+ p[3] = n;
+}
+
+/* Read a 16-bit unsigned int in Java byte order (i.e. big
+ endian.) */
+
+static uint16
+annotation_read_short (unsigned char *p)
+{
+ uint16 tmp = p[0];
+ tmp = (tmp << 8) | p[1];
+ return tmp;
+}
+
+/* annotation_write_TYPE. Rewrite various int types, appending them
+ to TYPE_REFLECTION_DATA. Use Java byte order (i.e. big
+ endian.) */
+
+static void
+annotation_write_byte (unsigned int n)
+{
+ annotation_rewrite_byte (n, annotation_grow (1));
+}
+
+static void
+annotation_write_short (unsigned int n)
+{
+ annotation_rewrite_short (n, annotation_grow (2));
+}
+
+static void
+annotation_write_int (unsigned int n)
+{
+ annotation_rewrite_int (n, annotation_grow (4));
+}
+
+/* Create a 64-bit constant in the constant pool.
+
+ This is used for both integer and floating-point types. As a
+ consequence, it will not work if the target floating-point format
+ is anything other than IEEE-754. While this is arguably a bug, the
+ runtime library makes exactly the same assumption and it's unlikely
+ that Java will ever run on a non-IEEE machine. */
+
+static int
+handle_long_constant (JCF *jcf, CPool *cpool, enum cpool_tag kind,
+ int index, bool big_endian)
+{
+ /* If we're on a 64-bit platform we can fit a long or double
+ into the same space as a jword. */
+ if (POINTER_SIZE >= 64)
+ index = find_constant1 (cpool, kind, JPOOL_LONG (jcf, index));
+
+ /* In a compiled program the constant pool is in native word
+ order. How weird is that??? */
+ else if (big_endian)
+ index = find_constant2 (cpool, kind,
+ JPOOL_INT (jcf, index),
+ JPOOL_INT (jcf, index+1));
+ else
+ index = find_constant2 (cpool, kind,
+ JPOOL_INT (jcf, index+1),
+ JPOOL_INT (jcf, index));
+
+ return index;
+}
+
+/* Given a class file and an index into its constant pool, create an
+ entry in the outgoing constant pool for the same item. */
+
+static uint16
+handle_constant (JCF *jcf, int index, enum cpool_tag purpose)
+{
+ unsigned int kind;
+ CPool *cpool = cpool_for_class (output_class);
+
+ if (index == 0)
+ return 0;
+
+ if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, index))
+ error ("", index);
+
+ kind = JPOOL_TAG (jcf, index);
+
+ if ((kind & ~CONSTANT_ResolvedFlag) != purpose)
+ {
+ if (purpose == CONSTANT_Class
+ && kind == CONSTANT_Utf8)
+ ;
+ else
+ error ("= 0) \
{ \
tree thrown_class = get_class_constant (jcf, JCF_readu2 (jcf)); \
- list = tree_cons (NULL_TREE, thrown_class, list); \
+ VEC_quick_push (tree, v, thrown_class); \
} \
- DECL_FUNCTION_THROWS (current_method) = nreverse (list); \
+ DECL_FUNCTION_THROWS (current_method) = v; \
}
#define HANDLE_DEPRECATED_ATTRIBUTE() handle_deprecated ()
@@ -224,16 +948,19 @@ set_source_filename (JCF *jcf, int index)
/* Link seen inner classes to their outer context and register the
inner class to its outer context. They will be later loaded. */
#define HANDLE_INNERCLASSES_ATTRIBUTE(COUNT) \
- handle_innerclass_attribute (COUNT, jcf)
+ handle_innerclass_attribute (COUNT, jcf, attribute_length)
#define HANDLE_SYNTHETIC_ATTRIBUTE() \
{ \
/* Irrelevant decls should have been nullified by the END macros. \
- We only handle the `Synthetic' attribute on method DECLs. \
DECL_ARTIFICIAL on fields is used for something else (See \
PUSH_FIELD in java-tree.h) */ \
if (current_method) \
DECL_ARTIFICIAL (current_method) = 1; \
+ else if (current_field) \
+ FIELD_SYNTHETIC (current_field) = 1; \
+ else \
+ TYPE_SYNTHETIC (current_class) = 1; \
}
#define HANDLE_GCJCOMPILED_ATTRIBUTE() \
@@ -242,17 +969,54 @@ set_source_filename (JCF *jcf, int index)
jcf->right_zip = 1; \
}
+#define HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE() \
+{ \
+ handle_member_annotations (index, jcf, name_data, attribute_length, attr_type); \
+}
+
+#define HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE() \
+{ \
+ JCF_SKIP(jcf, attribute_length); \
+}
+
+#define HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE() \
+{ \
+ handle_parameter_annotations (index, jcf, name_data, attribute_length, attr_type); \
+}
+
+#define HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE() \
+{ \
+ JCF_SKIP(jcf, attribute_length); \
+}
+
+#define HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE() \
+{ \
+ handle_default_annotation (index, jcf, name_data, attribute_length, attr_type); \
+}
+
+#define HANDLE_ENCLOSINGMETHOD_ATTRIBUTE() \
+{ \
+ handle_enclosingmethod_attribute (index, jcf, name_data, \
+ attribute_length, attr_type); \
+}
+
+#define HANDLE_SIGNATURE_ATTRIBUTE() \
+{ \
+ handle_signature_attribute (index, jcf, name_data, \
+ attribute_length, attr_type); \
+}
+
#include "jcf-reader.c"
tree
parse_signature (JCF *jcf, int sig_index)
{
- if (sig_index <= 0 || sig_index >= JPOOL_SIZE (jcf)
- || JPOOL_TAG (jcf, sig_index) != CONSTANT_Utf8)
- abort ();
- else
- return parse_signature_string (JPOOL_UTF_DATA (jcf, sig_index),
- JPOOL_UTF_LENGTH (jcf, sig_index));
+ gcc_assert (sig_index > 0
+ && sig_index < JPOOL_SIZE (jcf)
+ && JPOOL_TAG (jcf, sig_index) == CONSTANT_Utf8);
+
+ return parse_signature_string (JPOOL_UTF_DATA (jcf, sig_index),
+ JPOOL_UTF_LENGTH (jcf, sig_index));
}
tree
@@ -270,20 +1034,20 @@ get_constant (JCF *jcf, int index)
case CONSTANT_Integer:
{
jint num = JPOOL_INT(jcf, index);
- value = build_int_2 (num, num < 0 ? -1 : 0);
- TREE_TYPE (value) = int_type_node;
+ value = build_int_cst (int_type_node, num);
break;
}
case CONSTANT_Long:
{
- unsigned HOST_WIDE_INT num = JPOOL_UINT (jcf, index);
- HOST_WIDE_INT lo, hi;
- lshift_double (num, 0, 32, 64, &lo, &hi, 0);
- num = JPOOL_UINT (jcf, index+1);
- add_double (lo, hi, num, 0, &lo, &hi);
- value = build_int_2 (lo, hi);
- TREE_TYPE (value) = long_type_node;
- force_fit_type (value, 0);
+ unsigned HOST_WIDE_INT num;
+ double_int val;
+
+ num = JPOOL_UINT (jcf, index);
+ val = double_int_lshift (uhwi_to_double_int (num), 32, 64, false);
+ num = JPOOL_UINT (jcf, index + 1);
+ val = double_int_ior (val, uhwi_to_double_int (num));
+
+ value = double_int_to_tree (long_type_node, val);
break;
}
@@ -306,7 +1070,7 @@ get_constant (JCF *jcf, int index)
hi = JPOOL_UINT (jcf, index);
lo = JPOOL_UINT (jcf, index+1);
- if (FLOAT_WORDS_BIG_ENDIAN)
+ if (targetm.float_words_big_endian ())
buf[0] = hi, buf[1] = lo;
else
buf[0] = lo, buf[1] = hi;
@@ -357,10 +1121,7 @@ tree
get_name_constant (JCF *jcf, int index)
{
tree name = get_constant (jcf, index);
-
- if (TREE_CODE (name) != IDENTIFIER_NODE)
- abort ();
-
+ gcc_assert (TREE_CODE (name) == IDENTIFIER_NODE);
return name;
}
@@ -369,9 +1130,15 @@ get_name_constant (JCF *jcf, int index)
the outer context with the newly resolved innerclass. */
static void
-handle_innerclass_attribute (int count, JCF *jcf)
+handle_innerclass_attribute (int count, JCF *jcf, int attribute_length)
{
- int c = (count);
+ int c = count;
+
+ annotation_write_byte (JV_CLASS_ATTR);
+ annotation_write_int (attribute_length+1);
+ annotation_write_byte (JV_INNER_CLASSES_KIND);
+ annotation_write_short (count);
+
while (c--)
{
/* Read inner_class_info_index. This may be 0 */
@@ -384,11 +1151,17 @@ handle_innerclass_attribute (int count, JCF *jcf)
int ini = JCF_readu2 (jcf);
/* Read the access flag. */
int acc = JCF_readu2 (jcf);
+
+ annotation_write_short (handle_constant (jcf, icii, CONSTANT_Class));
+ annotation_write_short (handle_constant (jcf, ocii, CONSTANT_Class));
+ annotation_write_short (handle_constant (jcf, ini, CONSTANT_Utf8));
+ annotation_write_short (acc);
+
/* If icii is 0, don't try to read the class. */
if (icii >= 0)
{
- tree class = get_class_constant (jcf, icii);
- tree decl = TYPE_NAME (class);
+ tree klass = get_class_constant (jcf, icii);
+ tree decl = TYPE_NAME (klass);
/* Skip reading further if ocii is null */
if (DECL_P (decl) && !CLASS_COMPLETE_P (decl) && ocii)
{
@@ -407,24 +1180,34 @@ handle_innerclass_attribute (int count, JCF *jcf)
static tree
give_name_to_class (JCF *jcf, int i)
{
- if (i <= 0 || i >= JPOOL_SIZE (jcf)
- || JPOOL_TAG (jcf, i) != CONSTANT_Class)
- abort ();
- else
+ gcc_assert (i > 0
+ && i < JPOOL_SIZE (jcf)
+ && JPOOL_TAG (jcf, i) == CONSTANT_Class);
+
{
+ tree package_name = NULL_TREE, tmp;
tree this_class;
int j = JPOOL_USHORT1 (jcf, i);
/* verify_constant_pool confirmed that j is a CONSTANT_Utf8. */
- tree class_name = unmangle_classname (JPOOL_UTF_DATA (jcf, j),
+ tree class_name = unmangle_classname ((const char *) JPOOL_UTF_DATA (jcf, j),
JPOOL_UTF_LENGTH (jcf, j));
this_class = lookup_class (class_name);
- input_filename = DECL_SOURCE_FILE (TYPE_NAME (this_class));
- input_line = 0;
+ {
+ tree source_name = identifier_subst (class_name, "", '.', '/', ".java");
+ const char *sfname = find_sourcefile (IDENTIFIER_POINTER (source_name));
+ linemap_add (line_table, LC_ENTER, false, sfname, 0);
+ input_location = linemap_line_start (line_table, 0, 1);
+ file_start_location = input_location;
+ DECL_SOURCE_LOCATION (TYPE_NAME (this_class)) = input_location;
if (main_input_filename == NULL && jcf == main_jcf)
- main_input_filename = input_filename;
+ main_input_filename = sfname;
+ }
jcf->cpool.data[i].t = this_class;
JPOOL_TAG (jcf, i) = CONSTANT_ResolvedClass;
+ split_qualified_name (&package_name, &tmp,
+ DECL_NAME (TYPE_NAME (this_class)));
+ TYPE_PACKAGE (this_class) = package_name;
return this_class;
}
}
@@ -435,19 +1218,19 @@ tree
get_class_constant (JCF *jcf, int i)
{
tree type;
- if (i <= 0 || i >= JPOOL_SIZE (jcf)
- || (JPOOL_TAG (jcf, i) & ~CONSTANT_ResolvedFlag) != CONSTANT_Class)
- abort ();
+ gcc_assert (i > 0
+ && i < JPOOL_SIZE (jcf)
+ && (JPOOL_TAG (jcf, i) & ~CONSTANT_ResolvedFlag) == CONSTANT_Class);
if (JPOOL_TAG (jcf, i) != CONSTANT_ResolvedClass)
{
int name_index = JPOOL_USHORT1 (jcf, i);
/* verify_constant_pool confirmed that name_index is a CONSTANT_Utf8. */
- const char *name = JPOOL_UTF_DATA (jcf, name_index);
+ const char *name = (const char *) JPOOL_UTF_DATA (jcf, name_index);
int nlength = JPOOL_UTF_LENGTH (jcf, name_index);
if (name[0] == '[') /* Handle array "classes". */
- type = TREE_TYPE (parse_signature_string (name, nlength));
+ type = TREE_TYPE (parse_signature_string ((const unsigned char *) name, nlength));
else
{
tree cname = unmangle_classname (name, nlength);
@@ -470,85 +1253,54 @@ int
read_class (tree name)
{
JCF this_jcf, *jcf;
- tree icv, class = NULL_TREE;
+ tree icv, klass = NULL_TREE;
tree save_current_class = current_class;
+ tree save_output_class = output_class;
location_t save_location = input_location;
JCF *save_current_jcf = current_jcf;
if ((icv = IDENTIFIER_CLASS_VALUE (name)) != NULL_TREE)
{
- class = TREE_TYPE (icv);
- jcf = TYPE_JCF (class);
+ klass = TREE_TYPE (icv);
+ jcf = TYPE_JCF (klass);
}
else
jcf = NULL;
if (jcf == NULL)
{
+ const char* path_name;
this_jcf.zipd = NULL;
jcf = &this_jcf;
- if (find_class (IDENTIFIER_POINTER (name), IDENTIFIER_LENGTH (name),
- &this_jcf, 1) == 0)
+
+ path_name = find_class (IDENTIFIER_POINTER (name),
+ IDENTIFIER_LENGTH (name),
+ &this_jcf);
+ if (path_name == 0)
return 0;
+ else
+ free(CONST_CAST (char *, path_name));
}
current_jcf = jcf;
- if (current_jcf->java_source)
+ if (klass == NULL_TREE || ! CLASS_PARSED_P (klass))
{
- const char *filename = current_jcf->filename;
- tree file;
- FILE *finput;
- int generate;
-
- java_parser_context_save_global ();
- java_push_parser_context ();
- BUILD_FILENAME_IDENTIFIER_NODE (file, filename);
- generate = IS_A_COMMAND_LINE_FILENAME_P (file);
- if (wfl_operator == NULL_TREE)
- wfl_operator = build_expr_wfl (NULL_TREE, NULL, 0, 0);
- EXPR_WFL_FILENAME_NODE (wfl_operator) = file;
- input_filename = ggc_strdup (filename);
- current_class = NULL_TREE;
- current_function_decl = NULL_TREE;
- if (!HAS_BEEN_ALREADY_PARSED_P (file))
- {
- if (!(finput = fopen (input_filename, "r")))
- fatal_error ("can't reopen %s: %m", input_filename);
- parse_source_file_1 (file, finput);
- parse_source_file_2 ();
- parse_source_file_3 ();
- if (fclose (finput))
- fatal_error ("can't close %s: %m", input_filename);
- }
- JCF_FINISH (current_jcf);
- java_pop_parser_context (generate);
- java_parser_context_restore_global ();
- }
- else
- {
- if (class == NULL_TREE || ! CLASS_PARSED_P (class))
- {
- java_parser_context_save_global ();
- java_push_parser_context ();
- current_class = class;
- input_filename = current_jcf->filename;
- if (JCF_SEEN_IN_ZIP (current_jcf))
- read_zip_member(current_jcf,
- current_jcf->zipd, current_jcf->zipd->zipf);
- jcf_parse (current_jcf);
- /* Parsing might change the class, in which case we have to
- put it back where we found it. */
- if (current_class != class && icv != NULL_TREE)
- TREE_TYPE (icv) = current_class;
- class = current_class;
- java_pop_parser_context (0);
- java_parser_context_restore_global ();
- }
- layout_class (class);
- load_inner_classes (class);
+ output_class = current_class = klass;
+ if (JCF_SEEN_IN_ZIP (current_jcf))
+ read_zip_member(current_jcf,
+ current_jcf->zipd, current_jcf->zipd->zipf);
+ jcf_parse (current_jcf);
+ /* Parsing might change the class, in which case we have to
+ put it back where we found it. */
+ if (current_class != klass && icv != NULL_TREE)
+ TREE_TYPE (icv) = current_class;
+ klass = current_class;
}
+ layout_class (klass);
+ load_inner_classes (klass);
+ output_class = save_output_class;
current_class = save_current_class;
input_location = save_location;
current_jcf = save_current_jcf;
@@ -558,15 +1310,18 @@ read_class (tree name)
/* Load CLASS_OR_NAME. CLASS_OR_NAME can be a mere identifier if
called from the parser, otherwise it's a RECORD_TYPE node. If
VERBOSE is 1, print error message on failure to load a class. */
-
-/* Replace calls to load_class by having callers call read_class directly
- - and then perhaps rename read_class to load_class. FIXME */
-
void
load_class (tree class_or_name, int verbose)
{
tree name, saved;
- int class_loaded;
+ int class_loaded = 0;
+ tree class_decl = NULL_TREE;
+ bool is_compiled_class = false;
+
+ /* We've already failed, don't try again. */
+ if (TREE_CODE (class_or_name) == RECORD_TYPE
+ && TYPE_DUMMY (class_or_name))
+ return;
/* class_or_name can be the name of the class we want to load */
if (TREE_CODE (class_or_name) == IDENTIFIER_NODE)
@@ -579,31 +1334,84 @@ load_class (tree class_or_name, int verbose)
else
name = DECL_NAME (TYPE_NAME (class_or_name));
+ class_decl = IDENTIFIER_CLASS_VALUE (name);
+ if (class_decl != NULL_TREE)
+ {
+ tree type = TREE_TYPE (class_decl);
+ is_compiled_class
+ = ((TYPE_JCF (type) && JCF_SEEN_IN_ZIP (TYPE_JCF (type)))
+ || CLASS_FROM_CURRENTLY_COMPILED_P (type));
+ }
+
saved = name;
- while (1)
+
+ /* If flag_verify_invocations is unset, we don't try to load a class
+ unless we're looking for Object (which is fixed by the ABI) or
+ it's a class that we're going to compile. */
+ if (flag_verify_invocations
+ || class_or_name == object_type_node
+ || is_compiled_class
+ || TREE_CODE (class_or_name) == IDENTIFIER_NODE)
{
- char *separator;
+ while (1)
+ {
+ const char *separator;
- if ((class_loaded = read_class (name)))
- break;
+ /* We've already loaded it. */
+ if (IDENTIFIER_CLASS_VALUE (name) != NULL_TREE)
+ {
+ tree tmp_decl = IDENTIFIER_CLASS_VALUE (name);
+ if (CLASS_PARSED_P (TREE_TYPE (tmp_decl)))
+ break;
+ }
+
+ if (read_class (name))
+ break;
+
+ /* We failed loading name. Now consider that we might be looking
+ for an inner class. */
+ if ((separator = strrchr (IDENTIFIER_POINTER (name), '$'))
+ || (separator = strrchr (IDENTIFIER_POINTER (name), '.')))
+ name = get_identifier_with_length (IDENTIFIER_POINTER (name),
+ (separator
+ - IDENTIFIER_POINTER (name)));
+ /* Otherwise, we failed, we bail. */
+ else
+ break;
+ }
- /* We failed loading name. Now consider that we might be looking
- for a inner class. */
- if ((separator = strrchr (IDENTIFIER_POINTER (name), '$'))
- || (separator = strrchr (IDENTIFIER_POINTER (name), '.')))
+ {
+ /* have we found the class we're looking for? */
+ tree type_decl = IDENTIFIER_CLASS_VALUE (saved);
+ tree type = type_decl ? TREE_TYPE (type_decl) : NULL;
+ class_loaded = type && CLASS_PARSED_P (type);
+ }
+ }
+
+ if (!class_loaded)
+ {
+ if (flag_verify_invocations || ! flag_indirect_dispatch)
{
- int c = *separator;
- *separator = '\0';
- name = get_identifier (IDENTIFIER_POINTER (name));
- *separator = c;
+ if (verbose)
+ error ("cannot find file for class %s", IDENTIFIER_POINTER (saved));
+ }
+ else if (verbose)
+ {
+ /* This is just a diagnostic during testing, not a real problem. */
+ if (!quiet_flag)
+ warning (0, "cannot find file for class %s",
+ IDENTIFIER_POINTER (saved));
+
+ /* Fake it. */
+ if (TREE_CODE (class_or_name) == RECORD_TYPE)
+ {
+ set_super_info (0, class_or_name, object_type_node, 0);
+ TYPE_DUMMY (class_or_name) = 1;
+ /* We won't be able to output any debug info for this class. */
+ DECL_IGNORED_P (TYPE_NAME (class_or_name)) = 1;
+ }
}
- /* Otherwise, we failed, we bail. */
- else
- break;
}
-
- if (!class_loaded && verbose)
- error ("cannot find file for class %s", IDENTIFIER_POINTER (saved));
}
/* Parse the .class file JCF. */
@@ -613,6 +1421,8 @@ jcf_parse (JCF* jcf)
{
int i, code;
+ bitmap_clear (field_offsets);
+
if (jcf_parse_preamble (jcf) != 0)
fatal_error ("not a valid Java .class file");
code = jcf_parse_constant_pool (jcf);
@@ -658,23 +1468,19 @@ jcf_parse (JCF* jcf)
if (code != 0)
fatal_error ("error while parsing final attributes");
+ if (TYPE_REFLECTION_DATA (current_class))
+ annotation_write_byte (JV_DONE_ATTR);
+
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+
/* The fields of class_type_node are already in correct order. */
if (current_class != class_type_node && current_class != object_type_node)
TYPE_FIELDS (current_class) = nreverse (TYPE_FIELDS (current_class));
if (current_class == object_type_node)
- {
- layout_class_methods (object_type_node);
- /* If we don't have the right archive, emit a verbose warning.
- If we're generating bytecode, emit the warning only if
- -fforce-classes-archive-check was specified. */
- if (!jcf->right_zip
- && (!flag_emit_class_files || flag_force_classes_archive_check))
- fatal_error ("the `java.lang.Object' that was found in `%s' didn't have the special zero-length `gnu.gcj.gcj-compiled' attribute. This generally means that your classpath is incorrectly set. Use `info gcj \"Input Options\"' to see the info page describing how to set the classpath", jcf->filename);
- }
+ layout_class_methods (object_type_node);
else
- all_class_list = tree_cons (NULL_TREE,
- TYPE_NAME (current_class), all_class_list );
+ VEC_safe_push (tree, gc, all_class_list, TYPE_NAME (current_class));
}
/* If we came across inner classes, load them now. */
@@ -693,10 +1499,50 @@ load_inner_classes (tree cur_class)
}
}
-void
-init_outgoing_cpool (void)
+static void
+duplicate_class_warning (const char *filename)
{
- outgoing_cpool = ggc_alloc_cleared (sizeof (struct CPool));
+ location_t warn_loc;
+ linemap_add (line_table, LC_RENAME, 0, filename, 0);
+ warn_loc = linemap_line_start (line_table, 0, 1);
+ warning_at (warn_loc, 0, "duplicate class will only be compiled once");
+}
+
+static void
+java_layout_seen_class_methods (void)
+{
+ unsigned start = 0;
+ unsigned end = VEC_length (tree, all_class_list);
+
+ while (1)
+ {
+ unsigned ix;
+ unsigned new_length;
+
+ for (ix = start; ix != end; ix++)
+ {
+ tree decl = VEC_index (tree, all_class_list, ix);
+ tree cls = TREE_TYPE (decl);
+
+ input_location = DECL_SOURCE_LOCATION (decl);
+
+ if (! CLASS_LOADED_P (cls))
+ load_class (cls, 0);
+
+ layout_class_methods (cls);
+ }
+
+ /* Note that new classes might have been added while laying out
+ methods, changing the value of all_class_list. */
+ new_length = VEC_length (tree, all_class_list);
+ if (end != new_length)
+ {
+ start = end;
+ end = new_length;
+ }
+ else
+ break;
+ }
}
static void
@@ -707,23 +1553,25 @@ parse_class_file (void)
java_layout_seen_class_methods ();
- input_filename = DECL_SOURCE_FILE (TYPE_NAME (current_class));
- input_line = 0;
+ input_location = DECL_SOURCE_LOCATION (TYPE_NAME (current_class));
+ {
+ /* Re-enter the current file. */
+ expanded_location loc = expand_location (input_location);
+ linemap_add (line_table, LC_ENTER, 0, loc.file, loc.line);
+ }
+ file_start_location = input_location;
(*debug_hooks->start_source_file) (input_line, input_filename);
- init_outgoing_cpool ();
-
- /* Currently we always have to emit calls to _Jv_InitClass when
- compiling from class files. */
- always_initialize_class_p = 1;
java_mark_class_local (current_class);
+ gen_indirect_dispatch_tables (current_class);
+
for (method = TYPE_METHODS (current_class);
- method != NULL_TREE; method = TREE_CHAIN (method))
+ method != NULL_TREE; method = DECL_CHAIN (method))
{
JCF *jcf = current_jcf;
- if (METHOD_ABSTRACT (method))
+ if (METHOD_ABSTRACT (method) || METHOD_DUMMY (method))
continue;
if (METHOD_NATIVE (method))
@@ -745,7 +1593,7 @@ parse_class_file (void)
DECL_MAX_LOCALS (method) = decl_max_locals;
start_java_method (method);
give_name_to_locals (jcf);
- expand_expr_stmt (build_jni_stub (method));
+ *get_stmts () = build_jni_stub (method);
end_java_method ();
continue;
}
@@ -757,11 +1605,12 @@ parse_class_file (void)
continue;
}
- input_line = 0;
+ input_location = DECL_SOURCE_LOCATION (TYPE_NAME (current_class));
if (DECL_LINENUMBERS_OFFSET (method))
{
- register int i;
- register unsigned char *ptr;
+ int i;
+ int min_line = 0;
+ unsigned char *ptr;
JCF_SEEK (jcf, DECL_LINENUMBERS_OFFSET (method));
linenumber_count = i = JCF_readu2 (jcf);
linenumber_table = ptr = jcf->read_ptr;
@@ -769,11 +1618,13 @@ parse_class_file (void)
for (ptr += 2; --i >= 0; ptr += 4)
{
int line = GET_u2 (ptr);
- /* Set initial lineno lineno to smallest linenumber.
+ /* Set initial input_line to smallest linenumber.
* Needs to be set before init_function_start. */
- if (input_line == 0 || line < input_line)
- input_line = line;
- }
+ if (min_line == 0 || line < min_line)
+ min_line = line;
+ }
+ if (min_line != 0)
+ input_location = linemap_line_start (line_table, min_line, 1);
}
else
{
@@ -787,108 +1638,118 @@ parse_class_file (void)
give_name_to_locals (jcf);
- /* Actually generate code. */
+ /* Bump up start_label_pc_this_method so we get a unique label number
+ and reset highest_label_pc_this_method. */
+ if (highest_label_pc_this_method >= 0)
+ {
+ /* We adjust to the next multiple of 1000. This is just a frill
+ so the last 3 digits of the label number match the bytecode
+ offset, which might make debugging marginally more convenient. */
+ start_label_pc_this_method
+ = ((((start_label_pc_this_method + highest_label_pc_this_method)
+ / 1000)
+ + 1)
+ * 1000);
+ highest_label_pc_this_method = -1;
+ }
+
+ /* Convert bytecode to trees. */
expand_byte_code (jcf, method);
end_java_method ();
}
- if (flag_emit_class_files)
- write_classfile (current_class);
-
finish_class ();
- (*debug_hooks->end_source_file) (save_location.line);
+ (*debug_hooks->end_source_file) (LOCATION_LINE (save_location));
input_location = save_location;
}
-/* Parse a source file, as pointed by the current value of INPUT_FILENAME. */
+static VEC(tree,gc) *predefined_filenames;
-static void
-parse_source_file_1 (tree file, FILE *finput)
+void
+add_predefined_file (tree name)
{
- int save_error_count = java_error_count;
- /* Mark the file as parsed */
- HAS_BEEN_ALREADY_PARSED_P (file) = 1;
-
- jcf_dependency_add_file (input_filename, 0);
-
- lang_init_source (1); /* Error msgs have no method prototypes */
-
- /* There's no point in trying to find the current encoding unless we
- are going to do something intelligent with it -- hence the test
- for iconv. */
-#if defined (HAVE_LOCALE_H) && defined (HAVE_ICONV) && defined (HAVE_LANGINFO_CODESET)
- setlocale (LC_CTYPE, "");
- if (current_encoding == NULL)
- current_encoding = nl_langinfo (CODESET);
-#endif
- if (current_encoding == NULL || *current_encoding == '\0')
- current_encoding = DEFAULT_ENCODING;
-
- /* Initialize the parser */
- java_init_lex (finput, current_encoding);
- java_parse_abort_on_error ();
-
- java_parse (); /* Parse and build partial tree nodes. */
- java_parse_abort_on_error ();
+ VEC_safe_push (tree, gc, predefined_filenames, name);
}
-/* Process a parsed source file, resolving names etc. */
-
-static void
-parse_source_file_2 (void)
+int
+predefined_filename_p (tree node)
{
- int save_error_count = java_error_count;
- java_complete_class (); /* Parse unsatisfied class decl. */
- java_parse_abort_on_error ();
-}
+ unsigned ix;
+ tree f;
-static void
-parse_source_file_3 (void)
-{
- int save_error_count = java_error_count;
- java_check_circular_reference (); /* Check on circular references */
- java_parse_abort_on_error ();
- java_fix_constructors (); /* Fix the constructors */
- java_parse_abort_on_error ();
- java_reorder_fields (); /* Reorder the fields */
-}
+ FOR_EACH_VEC_ELT (tree, predefined_filenames, ix, f)
+ if (f == node)
+ return 1;
-void
-add_predefined_file (tree name)
-{
- predef_filenames = tree_cons (NULL_TREE, name, predef_filenames);
+ return 0;
}
-int
-predefined_filename_p (tree node)
+/* Generate a function that does all static initialization for this
+ translation unit. */
+
+static void
+java_emit_static_constructor (void)
{
- tree iter;
+ tree body = NULL;
+
+ emit_register_classes (&body);
+ write_resource_constructor (&body);
- for (iter = predef_filenames; iter != NULL_TREE; iter = TREE_CHAIN (iter))
+ if (body)
{
- if (TREE_VALUE (iter) == node)
- return 1;
+ tree name = get_identifier ("_Jv_global_static_constructor");
+
+ tree decl
+ = build_decl (input_location, FUNCTION_DECL, name,
+ build_function_type_list (void_type_node, NULL_TREE));
+
+ tree resdecl = build_decl (input_location,
+ RESULT_DECL, NULL_TREE, void_type_node);
+ DECL_ARTIFICIAL (resdecl) = 1;
+ DECL_RESULT (decl) = resdecl;
+ current_function_decl = decl;
+ allocate_struct_function (decl, false);
+
+ TREE_STATIC (decl) = 1;
+ TREE_USED (decl) = 1;
+ DECL_ARTIFICIAL (decl) = 1;
+ DECL_NO_INSTRUMENT_FUNCTION_ENTRY_EXIT (decl) = 1;
+ DECL_SAVED_TREE (decl) = body;
+ DECL_UNINLINABLE (decl) = 1;
+
+ DECL_INITIAL (decl) = make_node (BLOCK);
+ TREE_USED (DECL_INITIAL (decl)) = 1;
+
+ DECL_STATIC_CONSTRUCTOR (decl) = 1;
+ java_genericize (decl);
+ cgraph_finalize_function (decl, false);
}
- return 0;
}
+
void
-java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
+java_parse_file (void)
{
int filename_count = 0;
- char *list, *next;
+ location_t save_location = input_location;
+ char *file_list = NULL, *list, *next;
tree node;
FILE *finput = NULL;
+ int in_quotes = 0;
+ unsigned ix;
+
+ bitmap_obstack_initialize (&bit_obstack);
+ field_offsets = BITMAP_ALLOC (&bit_obstack);
if (flag_filelist_file)
{
int avail = 2000;
- finput = fopen (input_filename, "r");
+ finput = fopen (main_input_filename, "r");
if (finput == NULL)
- fatal_error ("can't open %s: %m", input_filename);
- list = xmalloc(avail);
+ fatal_error ("can%'t open %s: %m", input_filename);
+ list = XNEWVEC (char, avail);
next = list;
for (;;)
{
@@ -897,11 +1758,11 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
{
count = next - list;
avail = 2 * (count + avail);
- list = xrealloc (list, avail);
+ list = XRESIZEVEC (char, list, avail);
next = list + count;
avail = avail - count;
}
- /* Subtract to to guarantee space for final '\0'. */
+ /* Subtract one to guarantee space for final '\0'. */
count = fread (next, 1, avail - 1, finput);
if (count == 0)
{
@@ -915,17 +1776,19 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
}
fclose (finput);
finput = NULL;
+ file_list = list;
}
else
- list = xstrdup (input_filename);
+ list = CONST_CAST (char *, main_input_filename);
- do
+ while (list)
{
for (next = list; ; )
{
char ch = *next;
- if (ch == '\n' || ch == '\r' || ch == '\t' || ch == ' '
- || ch == '&' /* FIXME */)
+ if (flag_filelist_file && ! in_quotes
+ && (ch == '\n' || ch == '\r' || ch == '\t' || ch == ' '
+ || ch == '&') /* FIXME */)
{
if (next == list)
{
@@ -939,6 +1802,15 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
break;
}
}
+ if (flag_filelist_file && ch == '"')
+ {
+ in_quotes = ! in_quotes;
+ *next++ = '\0';
+ if (in_quotes)
+ list = next;
+ else
+ break;
+ }
if (ch == '\0')
{
next = NULL;
@@ -947,100 +1819,79 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
next++;
}
- if (list[0])
+ /* Exclude .java files. */
+ if (strlen (list) > 5 && ! strcmp (list + strlen (list) - 5, ".java"))
{
- char *value;
- tree id;
- int twice = 0;
-
- int len = strlen (list);
-
- obstack_grow0 (&temporary_obstack, list, len);
- value = obstack_finish (&temporary_obstack);
+ /* Nothing. */
+ }
+ else if (list[0])
+ {
+ node = get_identifier (list);
filename_count++;
- /* Exclude file that we see twice on the command line. For
- all files except {Class,Error,Object,RuntimeException,String,
- Throwable}.java we can rely on maybe_get_identifier. For
- these files, we need to do a linear search of
- current_file_list. This search happens only for these
- files, presumably only when we're recompiling libgcj. */
+ /* Exclude file that we see twice on the command line. */
- if ((id = maybe_get_identifier (value)))
- {
- if (predefined_filename_p (id))
- {
- tree c;
- for (c = current_file_list; c; c = TREE_CHAIN (c))
- if (TREE_VALUE (c) == id)
- twice = 1;
- }
- else
- twice = 1;
- }
-
- if (twice)
- {
- location_t warn_loc;
- warn_loc.file = value;
- warn_loc.line = 0;
- warning ("%Hsource file seen twice on command line and "
- "will be compiled only once", &warn_loc);
- }
+ if (IS_A_COMMAND_LINE_FILENAME_P (node))
+ duplicate_class_warning (IDENTIFIER_POINTER (node));
else
{
- BUILD_FILENAME_IDENTIFIER_NODE (node, value);
+ build_translation_unit_decl (node);
IS_A_COMMAND_LINE_FILENAME_P (node) = 1;
- current_file_list = tree_cons (NULL_TREE, node,
- current_file_list);
}
}
list = next;
}
- while (next);
+
+ free (file_list);
if (filename_count == 0)
- warning ("no input file specified");
+ warning (0, "no input file specified");
if (resource_name)
{
const char *resource_filename;
/* Only one resource file may be compiled at a time. */
- assert (TREE_CHAIN (current_file_list) == NULL);
+ gcc_assert (VEC_length (tree, all_translation_units) == 1);
- resource_filename = IDENTIFIER_POINTER (TREE_VALUE (current_file_list));
+ resource_filename
+ = IDENTIFIER_POINTER
+ (DECL_NAME (VEC_index (tree, all_translation_units, 0)));
compile_resource_file (resource_name, resource_filename);
- return;
+ goto finish;
}
current_jcf = main_jcf;
- current_file_list = nreverse (current_file_list);
- for (node = current_file_list; node; node = TREE_CHAIN (node))
+ FOR_EACH_VEC_ELT (tree, all_translation_units, ix, node)
{
unsigned char magic_string[4];
+ char *real_path;
uint32 magic = 0;
- tree name = TREE_VALUE (node);
+ tree name = DECL_NAME (node);
+ tree real_file;
+ const char *filename = IDENTIFIER_POINTER (name);
/* Skip already parsed files */
- if (HAS_BEEN_ALREADY_PARSED_P (name))
+ real_path = lrealpath (filename);
+ real_file = get_identifier (real_path);
+ free (real_path);
+ if (HAS_BEEN_ALREADY_PARSED_P (real_file))
continue;
-
+
/* Close previous descriptor, if any */
if (finput && fclose (finput))
- fatal_error ("can't close input file %s: %m", main_input_filename);
+ fatal_error ("can%'t close input file %s: %m", main_input_filename);
- finput = fopen (IDENTIFIER_POINTER (name), "rb");
+ finput = fopen (filename, "rb");
if (finput == NULL)
- fatal_error ("can't open %s: %m", IDENTIFIER_POINTER (name));
+ fatal_error ("can%'t open %s: %m", filename);
#ifdef IO_BUFFER_SIZE
setvbuf (finput, xmalloc (IO_BUFFER_SIZE),
_IOFBF, IO_BUFFER_SIZE);
#endif
- input_filename = IDENTIFIER_POINTER (name);
/* Figure what kind of file we're dealing with */
if (fread (magic_string, 1, 4, finput) == 4)
@@ -1051,62 +1902,66 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
if (magic == 0xcafebabe)
{
CLASS_FILE_P (node) = 1;
- current_jcf = ggc_alloc (sizeof (JCF));
- JCF_ZERO (current_jcf);
+ current_jcf = ggc_alloc_cleared_JCF ();
current_jcf->read_state = finput;
current_jcf->filbuf = jcf_filbuf_from_stdio;
jcf_parse (current_jcf);
+ DECL_SOURCE_LOCATION (node) = file_start_location;
TYPE_JCF (current_class) = current_jcf;
+ if (CLASS_FROM_CURRENTLY_COMPILED_P (current_class))
+ {
+ /* We've already compiled this class. */
+ duplicate_class_warning (filename);
+ continue;
+ }
CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1;
- TREE_PURPOSE (node) = current_class;
+ TREE_TYPE (node) = current_class;
}
else if (magic == (JCF_u4)ZIPMAGIC)
{
- ZIP_FILE_P (node) = 1;
- main_jcf = ggc_alloc (sizeof (JCF));
- JCF_ZERO (main_jcf);
+ main_jcf = ggc_alloc_cleared_JCF ();
main_jcf->read_state = finput;
main_jcf->filbuf = jcf_filbuf_from_stdio;
- if (open_in_zip (main_jcf, input_filename, NULL, 0) < 0)
- fatal_error ("bad zip/jar file %s", IDENTIFIER_POINTER (name));
+ linemap_add (line_table, LC_ENTER, false, filename, 0);
+ input_location = linemap_line_start (line_table, 0, 1);
+ if (open_in_zip (main_jcf, filename, NULL, 0) < 0)
+ fatal_error ("bad zip/jar file %s", filename);
localToFile = SeenZipFiles;
/* Register all the classes defined there. */
- process_zip_dir (main_jcf->read_state);
+ process_zip_dir ((FILE *) main_jcf->read_state);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
parse_zip_file_entries ();
- /*
- for (each entry)
- CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1;
- */
+ }
+ else if (magic == (JCF_u4) ZIPEMPTYMAGIC)
+ {
+ /* Ignore an empty input jar. */
}
else
{
- JAVA_FILE_P (node) = 1;
+ gcc_unreachable ();
+#if 0
java_push_parser_context ();
java_parser_context_save_global ();
- parse_source_file_1 (name, finput);
+
+ parse_source_file_1 (real_file, filename, finput);
java_parser_context_restore_global ();
java_pop_parser_context (1);
+ linemap_add (line_table, LC_LEAVE, false, NULL, 0);
+#endif
}
}
- for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next)
- {
- input_filename = ctxp->filename;
- parse_source_file_2 ();
- }
-
- for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next)
- {
- input_filename = ctxp->filename;
- parse_source_file_3 ();
- }
-
- for (node = current_file_list; node; node = TREE_CHAIN (node))
+ FOR_EACH_VEC_ELT (tree, all_translation_units, ix, node)
{
- input_filename = IDENTIFIER_POINTER (TREE_VALUE (node));
+ input_location = DECL_SOURCE_LOCATION (node);
if (CLASS_FILE_P (node))
{
- current_class = TREE_PURPOSE (node);
+ /* FIXME: These two flags really should be independent. We
+ should be able to compile fully binary compatible, but
+ with flag_verify_invocations on. */
+ flag_verify_invocations = ! flag_indirect_dispatch;
+ output_class = current_class = TREE_TYPE (node);
+
current_jcf = TYPE_JCF (current_class);
layout_class (current_class);
load_inner_classes (current_class);
@@ -1114,35 +1969,17 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED)
JCF_FINISH (current_jcf);
}
}
- input_filename = main_input_filename;
+ input_location = save_location;
- java_expand_classes ();
- if (!java_report_errors () && !flag_syntax_only)
- {
- /* Optimize and expand all classes compiled from source. */
- cgraph_finalize_compilation_unit ();
- cgraph_optimize ();
- java_finish_classes ();
-
- /* Emit the .jcf section. */
- emit_register_classes ();
- if (flag_indirect_dispatch)
- {
- otable_decl
- = emit_symbol_table
- (get_identifier ("otable"),
- otable_decl, otable_methods, otable_syms_decl, integer_type_node);
- atable_decl
- = emit_symbol_table
- (get_identifier ("atable"),
- atable_decl, atable_methods, atable_syms_decl, ptr_type_node);
- }
- emit_catch_table ();
- }
+ bitmap_obstack_release (&bit_obstack);
- write_resource_constructor ();
+ finish:
+ /* Arrange for any necessary initialization to happen. */
+ java_emit_static_constructor ();
+ gcc_assert (global_bindings_p ());
}
+
/* Return the name of the class corresponding to the name of the file
in this zip entry. The result is newly allocated using ALLOC. */
static char *
@@ -1150,13 +1987,24 @@ compute_class_name (struct ZipDirectory *zdir)
{
char *class_name_in_zip_dir = ZIPDIR_FILENAME (zdir);
char *class_name;
- int j;
+ int i;
+ int filename_length = zdir->filename_length;
+
+ while (filename_length > 2 && strncmp (class_name_in_zip_dir, "./", 2) == 0)
+ {
+ class_name_in_zip_dir += 2;
+ filename_length -= 2;
+ }
+
+ filename_length -= strlen (".class");
+ class_name = XNEWVEC (char, filename_length + 1);
+ memcpy (class_name, class_name_in_zip_dir, filename_length);
+ class_name [filename_length] = '\0';
+
+ for (i = 0; i < filename_length; i++)
+ if (class_name[i] == '/')
+ class_name[i] = '.';
- class_name = ALLOC (zdir->filename_length + 1 - 6);
- strncpy (class_name, class_name_in_zip_dir, zdir->filename_length - 6);
- class_name [zdir->filename_length - 6] = '\0';
- for (j = 0; class_name[j]; ++j)
- class_name[j] = class_name[j] == '/' ? '.' : class_name[j];
return class_name;
}
@@ -1195,7 +2043,7 @@ parse_zip_file_entries (void)
for (i = 0, zdir = (ZipDirectory *)localToFile->central_directory;
i < localToFile->count; i++, zdir = ZIPDIR_NEXT (zdir))
{
- tree class;
+ tree klass;
switch (classify_zip_file (zdir))
{
@@ -1205,14 +2053,40 @@ parse_zip_file_entries (void)
case 1:
{
char *class_name = compute_class_name (zdir);
- class = lookup_class (get_identifier (class_name));
+ int previous_alias_set = -1;
+ klass = lookup_class (get_identifier (class_name));
FREE (class_name);
- current_jcf = TYPE_JCF (class);
- current_class = class;
+ current_jcf = TYPE_JCF (klass);
+ output_class = current_class = klass;
+
+ /* This is a dummy class, and now we're compiling it for
+ real. */
+ gcc_assert (! TYPE_DUMMY (klass));
+
+ /* This is for a corner case where we have a superclass
+ but no superclass fields.
+
+ This can happen if we earlier failed to lay out this
+ class because its superclass was still in the process
+ of being laid out; this occurs when we have recursive
+ class dependencies via inner classes. We must record
+ the previous alias set and restore it after laying out
+ the class.
+
+ FIXME: this really is a kludge. We should figure out a
+ way to lay out the class properly before this
+ happens. */
+ if (TYPE_SIZE (klass) && CLASSTYPE_SUPER (klass)
+ && integer_zerop (TYPE_SIZE (klass)))
+ {
+ TYPE_SIZE (klass) = NULL_TREE;
+ previous_alias_set = TYPE_ALIAS_SET (klass);
+ TYPE_ALIAS_SET (klass) = -1;
+ }
- if (! CLASS_LOADED_P (class))
+ if (! CLASS_LOADED_P (klass))
{
- if (! CLASS_PARSED_P (class))
+ if (! CLASS_PARSED_P (klass))
{
read_zip_member (current_jcf, zdir, localToFile);
jcf_parse (current_jcf);
@@ -1221,11 +2095,13 @@ parse_zip_file_entries (void)
load_inner_classes (current_class);
}
+ if (previous_alias_set != -1)
+ TYPE_ALIAS_SET (klass) = previous_alias_set;
+
if (TYPE_SIZE (current_class) != error_mark_node)
{
- input_filename = current_jcf->filename;
parse_class_file ();
- FREE (current_jcf->buffer); /* No longer necessary */
+ free (current_jcf->buffer); /* No longer necessary */
/* Note: there is a way to free this buffer right after a
class seen in a zip file has been parsed. The idea is the
set its jcf in such a way that buffer will be reallocated
@@ -1238,15 +2114,14 @@ parse_zip_file_entries (void)
{
char *file_name, *class_name_in_zip_dir, *buffer;
JCF *jcf;
- file_name = ALLOC (zdir->filename_length + 1);
+ file_name = XNEWVEC (char, zdir->filename_length + 1);
class_name_in_zip_dir = ZIPDIR_FILENAME (zdir);
strncpy (file_name, class_name_in_zip_dir, zdir->filename_length);
file_name[zdir->filename_length] = '\0';
- jcf = ALLOC (sizeof (JCF));
+ jcf = XNEW (JCF);
JCF_ZERO (jcf);
jcf->read_state = finput;
jcf->filbuf = jcf_filbuf_from_stdio;
- jcf->java_source = 0;
jcf->classname = NULL;
jcf->filename = file_name;
jcf->zipd = zdir;
@@ -1254,7 +2129,7 @@ parse_zip_file_entries (void)
if (read_zip_member (jcf, zdir, localToFile) < 0)
fatal_error ("error while reading %s from zip file", file_name);
- buffer = ALLOC (zdir->filename_length + 1 +
+ buffer = XNEWVEC (char, zdir->filename_length + 1 +
(jcf->buffer_end - jcf->buffer));
strcpy (buffer, file_name);
/* This is not a typo: we overwrite the trailing \0 of the
@@ -1265,13 +2140,13 @@ parse_zip_file_entries (void)
compile_resource_data (file_name, buffer,
jcf->buffer_end - jcf->buffer);
JCF_FINISH (jcf);
- FREE (jcf);
- FREE (buffer);
+ free (jcf);
+ free (buffer);
}
break;
default:
- abort ();
+ gcc_unreachable ();
}
}
}
@@ -1289,7 +2164,7 @@ process_zip_dir (FILE *finput)
i < localToFile->count; i++, zdir = ZIPDIR_NEXT (zdir))
{
char *class_name, *file_name, *class_name_in_zip_dir;
- tree class;
+ tree klass;
JCF *jcf;
class_name_in_zip_dir = ZIPDIR_FILENAME (zdir);
@@ -1299,32 +2174,33 @@ process_zip_dir (FILE *finput)
continue;
class_name = compute_class_name (zdir);
- file_name = ALLOC (zdir->filename_length+1);
- jcf = ggc_alloc (sizeof (JCF));
- JCF_ZERO (jcf);
+ file_name = XNEWVEC (char, zdir->filename_length+1);
+ jcf = ggc_alloc_cleared_JCF ();
strncpy (file_name, class_name_in_zip_dir, zdir->filename_length);
file_name [zdir->filename_length] = '\0';
- class = lookup_class (get_identifier (class_name));
+ klass = lookup_class (get_identifier (class_name));
+
+ if (CLASS_FROM_CURRENTLY_COMPILED_P (klass))
+ {
+ /* We've already compiled this class. */
+ duplicate_class_warning (file_name);
+ continue;
+ }
+ /* This function is only called when processing a zip file seen
+ on the command line. */
+ CLASS_FROM_CURRENTLY_COMPILED_P (klass) = 1;
jcf->read_state = finput;
jcf->filbuf = jcf_filbuf_from_stdio;
- jcf->java_source = 0;
jcf->classname = class_name;
jcf->filename = file_name;
jcf->zipd = zdir;
- TYPE_JCF (class) = jcf;
+ TYPE_JCF (klass) = jcf;
}
}
-/* Initialization. */
-
-void
-init_jcf_parse (void)
-{
- init_src_parse ();
-}
-
#include "gt-java-jcf-parse.h"
+#include "gtype-java.h"