[PATCH] Java: jv-scan fixes and other small patches.

Alexandre Petit-Bianco apbianco@cygnus.com
Tue Mar 28 00:34:00 GMT 2000


I'm checking in this patch. It allows jv-scan to report inner classes
and also fixes the way `long' constants are read/written from/to class
files.

./A

2000-03-28  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* parse-scan.y (pop_class_context): Reset `inner_qualifier_length'
	to 0 when it reaches -1.

2000-03-27  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* jcf-parse.c (get_constant): Properly cast `num' during the
	invocation of `add_double call'.
	* jcf-write.c (push_long_const): Properly cast `lo' before
	comparing it to short bounds.
	* parse-scan.y (interface_declaration:): Rule re-arrange so that
	`interface_body:' is reduced after the current interface is
	pushed.

2000-02-28  Alexandre Petit-Bianco  <apbianco@cygnus.com>

	* parse-scan.y (inner_qualifier, inner_qualifier_length): New
	static globals.
	(push_class_context, pop_class_context): New function.
	(class_body:): Call pop_class_context.
	(interface_body:): Likewise.
	(INNER_QUALIFIER): New macro.
	(report_class_declaration): Changed output format and use
	INNER_QUALIFIER. Call push_class_context.

Index: jcf-parse.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/jcf-parse.c,v
retrieving revision 1.44
diff -u -p -r1.44 jcf-parse.c
--- jcf-parse.c	2000/03/14 05:01:04	1.44
+++ jcf-parse.c	2000/03/28 08:17:40
@@ -272,7 +272,7 @@ get_constant (jcf, index)
 	HOST_WIDE_INT lo, hi;
 	lshift_double (num, 0, 32, 64, &lo, &hi, 0);
 	num = JPOOL_INT (jcf, index+1);
-	add_double (lo, hi, num, 0, &lo, &hi);
+	add_double (lo, hi, (uint32)num, 0, &lo, &hi);
 	value = build_int_2 (lo, hi);
 	TREE_TYPE (value) = long_type_node;
 	force_fit_type (value, 0);
Index: jcf-write.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/jcf-write.c,v
retrieving revision 1.52
diff -u -p -r1.52 jcf-write.c
--- jcf-write.c	2000/03/23 07:01:23	1.52
+++ jcf-write.c	2000/03/28 08:17:47
@@ -845,7 +845,8 @@ push_long_const (lo, hi, state)
       RESERVE(1);
       OP1(OPCODE_lconst_0 + lo);
     }
-  else if ((hi == 0 && lo < 32768) || (hi == -1 && lo >= -32768))
+  else if ((hi == 0 && (jword)(lo  & 0xFFFFFFFF) < 32768) 
+          || (hi == -1 && (jword)(lo & 0xFFFFFFFF) >= -32768))
       {
         push_int_const (lo, state);
         RESERVE (1);
Index: parse-scan.y
===================================================================
RCS file: /cvs/gcc/egcs/gcc/java/parse-scan.y,v
retrieving revision 1.15
diff -u -p -r1.15 parse-scan.y
--- parse-scan.y	2000/01/21 20:57:00	1.15
+++ parse-scan.y	2000/03/28 08:17:58
@@ -66,6 +66,10 @@ static int absorber;
 static const char *current_class;
 static const char *package_name;
 
+/* Keep track of the current inner class qualifier. */
+static char *inner_qualifier;
+static int   inner_qualifier_length;
+
 /* Keep track of whether things have be listed before.  */
 static int previous_output;
 
@@ -92,6 +96,8 @@ struct method_declarator {
 /* Two actions for this grammar */
 static void report_class_declaration PARAMS ((const char *));
 static void report_main_declaration PARAMS ((struct method_declarator *));
+static void push_class_context PARAMS ((const char *));
+static void pop_class_context PARAMS ((void));
 
 #include "lex.h"
 #include "parse.h"
@@ -357,7 +363,9 @@ interface_type_list:
 
 class_body:
 	OCB_TK CCB_TK
+		{ pop_class_context (); }
 |	OCB_TK class_body_declarations CCB_TK
+		{ pop_class_context (); }
 ;
 
 class_body_declarations:
@@ -564,14 +572,18 @@ this_or_super:			/* Added, simplifies er
 /* 19.9 Productions from 9: Interfaces  */
 /* 19.9.1 Productions from 9.1: Interfaces Declarations  */
 interface_declaration:
-	INTERFACE_TK identifier	interface_body
+	INTERFACE_TK identifier
 		{ report_class_declaration ($2); modifier_value = 0; }
-|	modifiers INTERFACE_TK identifier interface_body
+	interface_body
+|	modifiers INTERFACE_TK identifier
 		{ report_class_declaration ($3); modifier_value = 0; }
-|	INTERFACE_TK identifier extends_interfaces interface_body
+	interface_body
+|	INTERFACE_TK identifier extends_interfaces
 		{ report_class_declaration ($2); modifier_value = 0; }
-|	modifiers INTERFACE_TK identifier extends_interfaces interface_body
+	interface_body
+|	modifiers INTERFACE_TK identifier extends_interfaces
 		{ report_class_declaration ($3); modifier_value = 0; }
+	interface_body
 ;
 
 extends_interfaces:
@@ -581,7 +593,9 @@ extends_interfaces:
 
 interface_body:
 	OCB_TK CCB_TK
+		{ pop_class_context (); }
 |	OCB_TK interface_member_declarations CCB_TK
+		{ pop_class_context (); }
 ;
 
 interface_member_declarations:
@@ -1110,7 +1124,33 @@ java_push_parser_context ()
   ctxp = new;
 }  
 
+static void
+push_class_context (name)
+    const char *name;
+{
+  size_t name_length = strlen (name);
+  inner_qualifier = xrealloc (inner_qualifier, 
+                             inner_qualifier_length + name_length+2);
+  memcpy (inner_qualifier+inner_qualifier_length, name, name_length);
+  inner_qualifier_length += name_length;
+  inner_qualifier [inner_qualifier_length] = '$';
+  inner_qualifier [++inner_qualifier_length] = '\0';
+}
+
+static void
+pop_class_context ()
+{
+  while (--inner_qualifier_length > 0
+        && inner_qualifier [inner_qualifier_length-1] != '$')
+    ;
+  inner_qualifier = xrealloc (inner_qualifier, inner_qualifier_length+1);
+  inner_qualifier [inner_qualifier_length] = '\0';
+  if (inner_qualifier_length == -1)
+    inner_qualifier_length = 0;
+}
+
 /* Actions defined here */
+#define INNER_QUALIFIER (inner_qualifier ? inner_qualifier : "")
 
 static void
 report_class_declaration (name)
@@ -1128,11 +1168,12 @@ report_class_declaration (name)
 	}
 	
       if (package_name)
-	fprintf (out, "%s.%s ", package_name, name);
+	fprintf (out, "%s.%s%s ", package_name, INNER_QUALIFIER, name);
       else
-	fprintf (out, "%s ", name);
+	fprintf (out, "%s%s ", INNER_QUALIFIER, name);
     }
-      
+
+  push_class_context (name);
   current_class = name;
 }
 


More information about the Gcc-patches mailing list