diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /gcc/java/jcf-parse.c | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'gcc/java/jcf-parse.c')
-rw-r--r-- | gcc/java/jcf-parse.c | 963 |
1 files changed, 847 insertions, 116 deletions
diff --git a/gcc/java/jcf-parse.c b/gcc/java/jcf-parse.c index 9f0ccaa..079228e 100644 --- a/gcc/java/jcf-parse.c +++ b/gcc/java/jcf-parse.c @@ -1,6 +1,6 @@ /* Parser for Java(TM) .class files. - Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. + Copyright (C) 1996, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006, 2007 Free Software Foundation, Inc. This file is part of GCC. @@ -35,6 +35,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "flags.h" #include "java-except.h" #include "input.h" +#include "javaop.h" #include "java-tree.h" #include "toplev.h" #include "parse.h" @@ -43,6 +44,7 @@ The Free Software Foundation is independent of Sun Microsystems, Inc. */ #include "assert.h" #include "tm_p.h" #include "cgraph.h" +#include "vecprim.h" #ifdef HAVE_LOCALE_H #include <locale.h> @@ -89,23 +91,32 @@ static location_t file_start_location; /* The Java archive that provides main_class; the main input file. */ static GTY(()) struct JCF * main_jcf; +/* The number of source files passd 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, const char *, 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 @@ -124,6 +135,181 @@ handle_deprecated (void) } } + + +/* Reverse a string. */ +static char * +reverse (const char *s) +{ + if (s == NULL) + return NULL; + else + { + int len = strlen (s); + char *d = xmalloc (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(*(char **) p1, *(char **) 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") + && strcmp ((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 = alloca (longest_line + 1); + int i = 0; + int charpos; + + filenames = xmalloc (num_files * sizeof (char*)); + + 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 = xmalloc (sizeof (char*)); + 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 hierarcies 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 @@ -144,6 +330,7 @@ set_source_filename (JCF *jcf, int index) || old_filename[old_len - new_len - 1] == '\\')) { #ifndef USE_MAPPED_LOCATION + input_filename = find_sourcefile (input_filename); DECL_SOURCE_LOCATION (TYPE_NAME (current_class)) = input_location; file_start_location = input_location; #endif @@ -177,6 +364,7 @@ set_source_filename (JCF *jcf, int index) } } + sfname = find_sourcefile (sfname); #ifdef USE_MAPPED_LOCATION line_table.maps[line_table.used-1].to_file = sfname; #else @@ -187,6 +375,519 @@ set_source_filename (JCF *jcf, int index) 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 ouput file. We don't decode the + data at all, merely rewriting constant indexes whenever we come + across them: this is necessary becasue the constant pool in the + output file isn't the same as the constant pool in 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 + peformance 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 = xmalloc (delta); + } + else + { + int newlen = *datasize + delta; + if (floor_log2 (newlen) != floor_log2 (*datasize)) + *data = xrealloc (*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) +{ + enum cpool_tag kind; + CPool *cpool = cpool_for_class (output_class); + + if (index == 0) + return 0; + + if (! CPOOL_INDEX_IN_RANGE (&jcf->cpool, index)) + error ("<constant pool index %d not in range>", index); + + kind = JPOOL_TAG (jcf, index); + + if ((kind & ~CONSTANT_ResolvedFlag) != purpose) + { + if (purpose == CONSTANT_Class + && kind == CONSTANT_Utf8) + ; + else + error ("<constant pool index %d unexpected type", index); + } + + switch (kind) + { + case CONSTANT_Class: + case CONSTANT_ResolvedClass: + { + /* For some reason I know not the what of, class names in + annotations are UTF-8 strings in the constant pool but + class names in EnclosingMethod attributes are real class + references. Set CONSTANT_LazyFlag here so that the VM + doesn't attempt to resolve them at class initialization + time. */ + tree resolved_class, class_name; + resolved_class = get_class_constant (jcf, index); + class_name = build_internal_class_name (resolved_class); + index = alloc_name_constant (CONSTANT_Class | CONSTANT_LazyFlag, + (unmangle_classname + (IDENTIFIER_POINTER(class_name), + IDENTIFIER_LENGTH(class_name)))); + break; + } + case CONSTANT_Utf8: + { + tree utf8 = get_constant (jcf, index); + if (purpose == CONSTANT_Class) + /* Create a constant pool entry for a type signature. This + one has '.' rather than '/' because it isn't going into a + class file, it's going into a compiled object. + + This has to match the logic in + _Jv_ClassReader::prepare_pool_entry(). */ + utf8 = unmangle_classname (IDENTIFIER_POINTER(utf8), + IDENTIFIER_LENGTH(utf8)); + index = alloc_name_constant (kind, utf8); + } + break; + + case CONSTANT_Long: + index = handle_long_constant (jcf, cpool, kind, index, + WORDS_BIG_ENDIAN); + break; + + case CONSTANT_Double: + index = handle_long_constant (jcf, cpool, kind, index, + FLOAT_WORDS_BIG_ENDIAN); + break; + + case CONSTANT_Float: + case CONSTANT_Integer: + index = find_constant1 (cpool, kind, JPOOL_INT (jcf, index)); + break; + + case CONSTANT_NameAndType: + { + uint16 name = JPOOL_USHORT1 (jcf, index); + uint16 sig = JPOOL_USHORT2 (jcf, index); + uint32 name_index = handle_constant (jcf, name, CONSTANT_Utf8); + uint32 sig_index = handle_constant (jcf, sig, CONSTANT_Class); + jword new_index = (name_index << 16) | sig_index; + index = find_constant1 (cpool, kind, new_index); + } + break; + + default: + abort (); + } + + return index; +} + +/* Read an element_value structure from an annotation in JCF. Return + the constant pool index for the resulting constant pool entry. */ + +static int +handle_element_value (JCF *jcf, int level) +{ + uint8 tag = JCF_readu (jcf); + int index = 0; + + annotation_write_byte (tag); + switch (tag) + { + case 'B': + case 'C': + case 'S': + case 'Z': + case 'I': + { + uint16 cindex = JCF_readu2 (jcf); + index = handle_constant (jcf, cindex, + CONSTANT_Integer); + annotation_write_short (index); + } + break; + case 'D': + { + uint16 cindex = JCF_readu2 (jcf); + index = handle_constant (jcf, cindex, + CONSTANT_Double); + annotation_write_short (index); + } + break; + case 'F': + { + uint16 cindex = JCF_readu2 (jcf); + index = handle_constant (jcf, cindex, + CONSTANT_Float); + annotation_write_short (index); + } + break; + case 'J': + { + uint16 cindex = JCF_readu2 (jcf); + index = handle_constant (jcf, cindex, + CONSTANT_Long); + annotation_write_short (index); + } + break; + case 's': + { + uint16 cindex = JCF_readu2 (jcf); + /* Despite what the JVM spec says, compilers generate a Utf8 + constant here, not a String. */ + index = handle_constant (jcf, cindex, + CONSTANT_Utf8); + annotation_write_short (index); + } + break; + + case 'e': + { + uint16 type_name_index = JCF_readu2 (jcf); + uint16 const_name_index = JCF_readu2 (jcf); + index = handle_constant (jcf, type_name_index, + CONSTANT_Class); + annotation_write_short (index); + index = handle_constant (jcf, const_name_index, + CONSTANT_Utf8); + annotation_write_short (index); + } + break; + case 'c': + { + uint16 class_info_index = JCF_readu2 (jcf); + index = handle_constant (jcf, class_info_index, + CONSTANT_Class); + annotation_write_short (index); + } + break; + case '@': + { + handle_annotation (jcf, level + 1); + } + break; + case '[': + { + uint16 n_array_elts = JCF_readu2 (jcf); + annotation_write_short (n_array_elts); + while (n_array_elts--) + handle_element_value (jcf, level + 1); + } + break; + default: + abort(); + break; + } + return index; +} + +/* Read an annotation structure from JCF. Write it to the + reflection_data field of the outgoing class. */ + +static void +handle_annotation (JCF *jcf, int level) +{ + uint16 type_index = JCF_readu2 (jcf); + uint16 npairs = JCF_readu2 (jcf); + int index = handle_constant (jcf, type_index, + CONSTANT_Class); + annotation_write_short (index); + annotation_write_short (npairs); + while (npairs--) + { + uint16 name_index = JCF_readu2 (jcf); + index = handle_constant (jcf, name_index, + CONSTANT_Utf8); + annotation_write_short (index); + handle_element_value (jcf, level + 2); + } +} + +/* Read an annotation count from JCF, and write the following + annotatons to the reflection_data field of the outgoing class. */ + +static void +handle_annotations (JCF *jcf, int level) +{ + uint16 num = JCF_readu2 (jcf); + annotation_write_short (num); + while (num--) + handle_annotation (jcf, level); +} + +/* As handle_annotations(), but perform a sanity check that we write + the same number of bytes that we were expecting. */ + +static void +handle_annotation_attribute (int ATTRIBUTE_UNUSED index, JCF *jcf, + long length) +{ + long old_datasize = TYPE_REFLECTION_DATASIZE (current_class); + + handle_annotations (jcf, 0); + + gcc_assert (old_datasize + length + == TYPE_REFLECTION_DATASIZE (current_class)); +} + +/* gcj permutes its fields array after generating annotation_data, so + we have to fixup field indexes for fields that have moved. Given + ARG, a VEC_int, fixup the field indexes in the reflection_data of + the outgoing class. We use field_offsets to tell us where the + fixups must go. */ + +void +rewrite_reflection_indexes (void *arg) +{ + bitmap_iterator bi; + unsigned int offset; + VEC(int, heap) *map = arg; + unsigned char *data = TYPE_REFLECTION_DATA (current_class); + + if (map) + { + EXECUTE_IF_SET_IN_BITMAP (field_offsets, 0, offset, bi) + { + uint16 index = annotation_read_short (data + offset); + annotation_rewrite_short + (VEC_index (int, map, index), data + offset); + } + } +} + +/* Read the RuntimeVisibleAnnotations from JCF and write them to the + reflection_data of the outgoing class. */ + +static void +handle_member_annotations (int member_index, JCF *jcf, + const unsigned char *name ATTRIBUTE_UNUSED, + long len, jv_attr_type member_type) +{ + int new_len = len + 1; + annotation_write_byte (member_type); + if (member_type != JV_CLASS_ATTR) + new_len += 2; + annotation_write_int (new_len); + annotation_write_byte (JV_ANNOTATIONS_KIND); + if (member_type == JV_FIELD_ATTR) + bitmap_set_bit (field_offsets, TYPE_REFLECTION_DATASIZE (current_class)); + if (member_type != JV_CLASS_ATTR) + annotation_write_short (member_index); + handle_annotation_attribute (member_index, jcf, len); +} + +/* Read the RuntimeVisibleParameterAnnotations from JCF and write them + to the reflection_data of the outgoing class. */ + +static void +handle_parameter_annotations (int member_index, JCF *jcf, + const unsigned char *name ATTRIBUTE_UNUSED, + long len, jv_attr_type member_type) +{ + int new_len = len + 1; + uint8 num; + annotation_write_byte (member_type); + if (member_type != JV_CLASS_ATTR) + new_len += 2; + annotation_write_int (new_len); + annotation_write_byte (JV_PARAMETER_ANNOTATIONS_KIND); + if (member_type != JV_CLASS_ATTR) + annotation_write_short (member_index); + num = JCF_readu (jcf); + annotation_write_byte (num); + while (num--) + handle_annotations (jcf, 0); +} + + +/* Read the AnnotationDefault data from JCF and write them to the + reflection_data of the outgoing class. */ + +static void +handle_default_annotation (int member_index, JCF *jcf, + const unsigned char *name ATTRIBUTE_UNUSED, + long len, jv_attr_type member_type) +{ + int new_len = len + 1; + annotation_write_byte (member_type); + if (member_type != JV_CLASS_ATTR) + new_len += 2; + annotation_write_int (new_len); + annotation_write_byte (JV_ANNOTATION_DEFAULT_KIND); + if (member_type != JV_CLASS_ATTR) + annotation_write_short (member_index); + handle_element_value (jcf, 0); +} + +/* As above, for the EnclosingMethod attribute. */ + +static void +handle_enclosingmethod_attribute (int member_index, JCF *jcf, + const unsigned char *name ATTRIBUTE_UNUSED, + long len, jv_attr_type member_type) +{ + int new_len = len + 1; + uint16 index; + annotation_write_byte (member_type); + if (member_type != JV_CLASS_ATTR) + new_len += 2; + annotation_write_int (new_len); + annotation_write_byte (JV_ENCLOSING_METHOD_KIND); + if (member_type != JV_CLASS_ATTR) + annotation_write_short (member_index); + + index = JCF_readu2 (jcf); + index = handle_constant (jcf, index, CONSTANT_Class); + annotation_write_short (index); + + index = JCF_readu2 (jcf); + index = handle_constant (jcf, index, CONSTANT_NameAndType); + annotation_write_short (index); +} + +/* As above, for the Signature attribute. */ + +static void +handle_signature_attribute (int member_index, JCF *jcf, + const unsigned char *name ATTRIBUTE_UNUSED, + long len, jv_attr_type member_type) +{ + int new_len = len + 1; + uint16 index; + annotation_write_byte (member_type); + if (member_type != JV_CLASS_ATTR) + new_len += 2; + annotation_write_int (new_len); + annotation_write_byte (JV_SIGNATURE_KIND); + if (member_type != JV_CLASS_ATTR) + annotation_write_short (member_index); + + index = JCF_readu2 (jcf); + index = handle_constant (jcf, index, CONSTANT_Utf8); + annotation_write_short (index); +} + + + #define HANDLE_SOURCEFILE(INDEX) set_source_filename (jcf, INDEX) #define HANDLE_CLASS_INFO(ACCESS_FLAGS, THIS, SUPER, INTERFACES_COUNT) \ @@ -262,16 +963,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 \ + CLASS_SYNTHETIC (current_class) = 1; \ } #define HANDLE_GCJCOMPILED_ATTRIBUTE() \ @@ -280,6 +984,43 @@ 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 @@ -403,9 +1144,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 */ @@ -418,6 +1165,12 @@ 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) { @@ -553,6 +1306,8 @@ read_class (tree name) if (current_jcf->java_source) { + gcc_unreachable (); +#if 0 const char *filename = current_jcf->filename; char *real_path; tree given_file, real_file; @@ -590,15 +1345,16 @@ read_class (tree name) JCF_FINISH (current_jcf); java_pop_parser_context (generate); java_parser_context_restore_global (); +#endif } else { if (class == NULL_TREE || ! CLASS_PARSED_P (class)) { - java_parser_context_save_global (); - java_push_parser_context (); +/* java_parser_context_save_global (); */ +/* java_push_parser_context (); */ output_class = current_class = class; - ctxp->save_location = input_location; +/* ctxp->save_location = input_location; */ if (JCF_SEEN_IN_ZIP (current_jcf)) read_zip_member(current_jcf, current_jcf->zipd, current_jcf->zipd->zipf); @@ -608,8 +1364,8 @@ read_class (tree name) 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 (); +/* java_pop_parser_context (0); */ +/* java_parser_context_restore_global (); */ } layout_class (class); load_inner_classes (class); @@ -789,6 +1545,10 @@ jcf_parse (JCF* jcf) code = jcf_parse_final_attributes (jcf); if (code != 0) fatal_error ("error while parsing final attributes"); + + if (TYPE_REFLECTION_DATA (current_class)) + annotation_write_byte (JV_DONE_ATTR); + #ifdef USE_MAPPED_LOCATION linemap_add (&line_table, LC_LEAVE, false, NULL, 0); #endif @@ -803,9 +1563,12 @@ jcf_parse (JCF* jcf) /* 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 0 + /* ECJ HACK: ignore this. */ if (!jcf->right_zip && (!flag_emit_class_files || flag_force_classes_archive_check)) fatal_error ("the %<java.lang.Object%> that was found in %qs 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); +#endif } else all_class_list = tree_cons (NULL_TREE, @@ -843,6 +1606,42 @@ duplicate_class_warning (const char *filename) } static void +java_layout_seen_class_methods (void) +{ + tree previous_list = all_class_list; + tree end = NULL_TREE; + tree current; + + while (1) + { + for (current = previous_list; + current != end; current = TREE_CHAIN (current)) + { + tree decl = TREE_VALUE (current); + 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. */ + + if (previous_list != all_class_list) + { + end = previous_list; + previous_list = all_class_list; + } + else + break; + } +} + +static void parse_class_file (void) { tree method; @@ -856,8 +1655,6 @@ parse_class_file (void) gen_indirect_dispatch_tables (current_class); - java_mark_class_local (current_class); - for (method = TYPE_METHODS (current_class); method != NULL_TREE; method = TREE_CHAIN (method)) { @@ -956,80 +1753,12 @@ parse_class_file (void) end_java_method (); } - if (flag_emit_class_files) - write_classfile (current_class); - finish_class (); (*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 void -parse_source_file_1 (tree real_file, const char *filename, FILE *finput) -{ - int save_error_count = java_error_count; - - /* Mark the file as parsed. */ - HAS_BEEN_ALREADY_PARSED_P (real_file) = 1; - - 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; - -#ifdef USE_MAPPED_LOCATION - linemap_add (&line_table, LC_ENTER, false, filename, 0); - input_location = linemap_line_start (&line_table, 0, 125); -#else - input_filename = filename; - input_line = 0; -#endif - ctxp->file_start_location = input_location; - ctxp->filename = filename; - - jcf_dependency_add_file (input_filename, 0); - - /* 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 (); -} - -/* Process a parsed source file, resolving names etc. */ - -static void -parse_source_file_2 (void) -{ - int save_error_count = java_error_count; - flag_verify_invocations = true; - java_complete_class (); /* Parse unsatisfied class decl. */ - java_parse_abort_on_error (); -} - -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 */ -} - void add_predefined_file (tree name) { @@ -1074,6 +1803,9 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) FILE *finput = NULL; int in_quotes = 0; + bitmap_obstack_initialize (&bit_obstack); + field_offsets = BITMAP_ALLOC (&bit_obstack); + if (flag_filelist_file) { int avail = 2000; @@ -1150,7 +1882,12 @@ 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")) + { + /* Nothing. */ + } + else if (list[0]) { node = get_identifier (list); @@ -1268,6 +2005,8 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) } else { + gcc_unreachable (); +#if 0 java_push_parser_context (); java_parser_context_save_global (); @@ -1277,19 +2016,15 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) #ifdef USE_MAPPED_LOCATION linemap_add (&line_table, LC_LEAVE, false, NULL, 0); #endif +#endif } } - for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next) - { - input_location = ctxp->file_start_location; - parse_source_file_2 (); - } - - for (ctxp = ctxp_for_generation; ctxp; ctxp = ctxp->next) + /* Do this before lowering any code. */ + for (node = current_file_list; node; node = TREE_CHAIN (node)) { - input_location = ctxp->file_start_location; - parse_source_file_3 (); + if (CLASS_FILE_P (node)) + java_mark_class_local (TREE_TYPE (node)); } for (node = current_file_list; node; node = TREE_CHAIN (node)) @@ -1312,12 +2047,14 @@ java_parse_file (int set_yydebug ATTRIBUTE_UNUSED) } input_location = save_location; - java_expand_classes (); - if (java_report_errors () || flag_syntax_only) - return; + bitmap_obstack_release (&bit_obstack); + +/* java_expand_classes (); */ +/* if (java_report_errors () || flag_syntax_only) */ +/* return; */ /* Expand all classes compiled from source. */ - java_finish_classes (); +/* java_finish_classes (); */ finish: /* Arrange for any necessary initialization to happen. */ @@ -1408,15 +2145,6 @@ parse_zip_file_entries (void) current_jcf = TYPE_JCF (class); output_class = current_class = class; - if (CLASS_FROM_CURRENTLY_COMPILED_P (current_class)) - { - /* We've already compiled this class. */ - duplicate_class_warning (current_jcf->filename); - break; - } - - CLASS_FROM_CURRENTLY_COMPILED_P (current_class) = 1; - /* This is a dummy class, and now we're compiling it for real. */ gcc_assert (! TYPE_DUMMY (class)); @@ -1531,6 +2259,16 @@ process_zip_dir (FILE *finput) class = lookup_class (get_identifier (class_name)); + if (CLASS_FROM_CURRENTLY_COMPILED_P (class)) + { + /* 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 (class) = 1; + jcf->read_state = finput; jcf->filbuf = jcf_filbuf_from_stdio; jcf->java_source = 0; @@ -1542,12 +2280,5 @@ process_zip_dir (FILE *finput) } } -/* Initialization. */ - -void -init_jcf_parse (void) -{ - init_src_parse (); -} - #include "gt-java-jcf-parse.h" +#include "gtype-java.h" |