/* This file read a Java(TM) .class file.
It is not stand-alone: It depends on tons of macros, and the
intent is you #include this file after you've defined the macros.
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- Free Software Foundation, Inc.
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2005, 2006,
+ 2007, 2008, 2010 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,
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
+<http://www.gnu.org/licenses/>.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
+#include "ggc.h"
#include "jcf.h"
#include "zipfile.h"
-static int get_attribute PARAMS ((JCF *));
-static int jcf_parse_preamble PARAMS ((JCF *));
-static int jcf_parse_constant_pool PARAMS ((JCF *));
-static void jcf_parse_class PARAMS ((JCF *));
-static int jcf_parse_fields PARAMS ((JCF *));
-static int jcf_parse_one_method PARAMS ((JCF *));
-static int jcf_parse_methods PARAMS ((JCF *));
-static int jcf_parse_final_attributes PARAMS ((JCF *));
+static int get_attribute (JCF *, int, jv_attr_type);
+static int jcf_parse_preamble (JCF *);
+static int jcf_parse_constant_pool (JCF *);
+static void jcf_parse_class (JCF *);
+static int jcf_parse_fields (JCF *);
+static int jcf_parse_one_method (JCF *, int);
+static int jcf_parse_methods (JCF *);
+static int jcf_parse_final_attributes (JCF *);
#ifdef NEED_PEEK_ATTRIBUTE
-static int peek_attribute PARAMS ((JCF *, int, const char *, int));
+static int peek_attribute (JCF *, int, const char *, int);
#endif
#ifdef NEED_SKIP_ATTRIBUTE
-static void skip_attribute PARAMS ((JCF *, int));
+static void skip_attribute (JCF *, int);
#endif
/* Go through all available attribute (ATTRIBUTE_NUMER) and try to
#ifdef NEED_PEEK_ATTRIBUTE /* Not everyone uses this function */
static int
-peek_attribute (jcf, attribute_number, peeked_name, peeked_name_length)
- JCF *jcf;
- int attribute_number;
- const char *peeked_name;
- int peeked_name_length;
+peek_attribute (JCF *jcf, int attribute_number, const char *peeked_name,
+ int peeked_name_length)
{
int to_return = 0;
long absolute_offset = (long)JCF_TELL (jcf);
#ifdef NEED_SKIP_ATTRIBUTE /* Not everyone uses this function */
static void
-skip_attribute (jcf, number_of_attribute)
- JCF *jcf;
- int number_of_attribute;
+skip_attribute (JCF *jcf, int number_of_attribute)
{
while (number_of_attribute--)
{
#endif
static int
-get_attribute (JCF *jcf)
+get_attribute (JCF *jcf, int index,
+ jv_attr_type attr_type ATTRIBUTE_UNUSED)
{
uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
uint32 attribute_length = JCF_readu4 (jcf);
attributes_count = JCF_readu2 (jcf);
for (j = 0; j < attributes_count; j++)
{
- int code = get_attribute (jcf);
+ int code = get_attribute (jcf, index, JV_METHOD_ATTR);
if (code != 0)
return code;
}
}
else
#endif
+#ifdef HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("LocalVariableTypeTable"))
+ {
+ uint16 count = JCF_readu2 (jcf);
+ HANDLE_LOCALVARIABLETYPETABLE_ATTRIBUTE (count);
+ }
+ else
+#endif
#ifdef HANDLE_INNERCLASSES_ATTRIBUTE
if (MATCH_ATTRIBUTE ("InnerClasses"))
{
}
else
#endif
+#ifdef HANDLE_DEPRECATED_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("Deprecated"))
+ {
+ HANDLE_DEPRECATED_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("SourceDebugExtension")) /* JSR 45 */
+ {
+ HANDLE_SOURCEDEBUGEXTENSION_ATTRIBUTE (attribute_length);
+ }
+ else
+#endif
+#ifdef HANDLE_ENCLOSINGMETHOD_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("EnclosingMethod"))
+ {
+ HANDLE_ENCLOSINGMETHOD_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_SIGNATURE_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("Signature"))
+ {
+ HANDLE_SIGNATURE_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeVisibleAnnotations"))
+ {
+ HANDLE_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeInvisibleAnnotations"))
+ {
+ HANDLE_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeVisibleParameterAnnotations"))
+ {
+ HANDLE_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("RuntimeInvisibleParameterAnnotations"))
+ {
+ HANDLE_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE ();
+ }
+ else
+#endif
+#ifdef HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE
+ if (MATCH_ATTRIBUTE ("AnnotationDefault"))
+ {
+ HANDLE_ANNOTATIONDEFAULT_ATTRIBUTE ();
+ }
+ else
+#endif
{
#ifdef PROCESS_OTHER_ATTRIBUTE
PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
{
int i, n;
JPOOL_SIZE (jcf) = (JCF_FILL (jcf, 2), JCF_readu2 (jcf));
- jcf->cpool.tags = ALLOC (JPOOL_SIZE (jcf));
- jcf->cpool.data = ALLOC (sizeof (jword) * JPOOL_SIZE (jcf));
+ jcf->cpool.tags = (uint8 *) ggc_alloc_atomic (JPOOL_SIZE (jcf));
+ jcf->cpool.data = ggc_alloc_cpool_entry (sizeof (jword) * JPOOL_SIZE (jcf));
jcf->cpool.tags[0] = 0;
#ifdef HANDLE_START_CONSTANT_POOL
HANDLE_START_CONSTANT_POOL (JPOOL_SIZE (jcf));
{
case CONSTANT_String:
case CONSTANT_Class:
- jcf->cpool.data[i] = JCF_readu2 (jcf);
+ jcf->cpool.data[i].w = JCF_readu2 (jcf);
break;
case CONSTANT_Fieldref:
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
case CONSTANT_NameAndType:
- jcf->cpool.data[i] = JCF_readu2 (jcf);
- jcf->cpool.data[i] |= JCF_readu2 (jcf) << 16;
+ jcf->cpool.data[i].w = JCF_readu2 (jcf);
+ jcf->cpool.data[i].w |= JCF_readu2 (jcf) << 16;
break;
case CONSTANT_Integer:
case CONSTANT_Float:
- jcf->cpool.data[i] = JCF_readu4 (jcf);
+ jcf->cpool.data[i].w = JCF_readu4 (jcf);
break;
case CONSTANT_Long:
case CONSTANT_Double:
- jcf->cpool.data[i] = JCF_readu4 (jcf);
+ jcf->cpool.data[i].w = JCF_readu4 (jcf);
i++; /* These take up two spots in the constant pool */
jcf->cpool.tags[i] = 0;
- jcf->cpool.data[i] = JCF_readu4 (jcf);
+ jcf->cpool.data[i].w = JCF_readu4 (jcf);
break;
case CONSTANT_Utf8:
n = JCF_readu2 (jcf);
#ifdef HANDLE_CONSTANT_Utf8
HANDLE_CONSTANT_Utf8(jcf, i, n);
#else
- jcf->cpool.data[i] = JCF_TELL(jcf) - 2;
+ jcf->cpool.data[i].w = JCF_TELL(jcf) - 2;
JCF_SKIP (jcf, n);
#endif
break;
#endif
for (j = 0; j < attribute_count; j++)
{
- int code = get_attribute (jcf);
+ int code = get_attribute (jcf, i, JV_FIELD_ATTR);
if (code != 0)
return code;
}
/* Read methods. */
static int
-jcf_parse_one_method (JCF* jcf)
+jcf_parse_one_method (JCF* jcf, int index)
{
int i;
uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
#endif
for (i = 0; i < attribute_count; i++)
{
- int code = get_attribute (jcf);
+ int code = get_attribute (jcf, index, JV_METHOD_ATTR);
if (code != 0)
return code;
}
#endif
for (i = 0; i < methods_count; i++)
{
- int code = jcf_parse_one_method (jcf);
+ int code = jcf_parse_one_method (jcf, i);
if (code != 0)
return code;
}
#endif
for (i = 0; i < attributes_count; i++)
{
- int code = get_attribute (jcf);
+ int code = get_attribute (jcf, i, JV_CLASS_ATTR);
if (code != 0)
return code;
}