OSDN Git Service

Fix typo in peep2 example.
[pf3gnuchains/gcc-fork.git] / gcc / java / parse-scan.y
index 25f87c8..dee5dc2 100644 (file)
@@ -41,6 +41,7 @@ definitions and other extensions.  */
 #include "system.h"
 
 #include "obstack.h"
+#include "toplev.h"
 
 extern char *input_filename;
 extern FILE *finput, *out;
@@ -62,8 +63,8 @@ static int absorber;
 #define USE_ABSORBER absorber = 0
 
 /* Keep track of the current class name and package name.  */
-static char *current_class;
-static char *package_name;
+static const char *current_class;
+static const char *package_name;
 
 /* Keep track of whether things have be listed before.  */
 static int previous_output;
@@ -77,8 +78,8 @@ static int bracket_count;
 
 /* Record a method declaration  */
 struct method_declarator {
-  char *method_name;
-  char *args;
+  const char *method_name;
+  const char *args;
 };
 #define NEW_METHOD_DECLARATOR(D,N,A)                                        \
 {                                                                           \
@@ -89,7 +90,7 @@ struct method_declarator {
 }
 
 /* Two actions for this grammar */
-static void report_class_declaration PROTO ((char *));
+static void report_class_declaration PROTO ((const char *));
 static void report_main_declaration PROTO ((struct method_declarator *));
 
 #include "lex.h"
@@ -102,6 +103,10 @@ static void report_main_declaration PROTO ((struct method_declarator *));
   int value;                   /* For modifiers */
 }
 
+%{
+#include "lex.c"
+%}
+
 %pure_parser
 
 /* Things defined here have to match the order of what's in the
@@ -226,17 +231,11 @@ array_type:
        primitive_type OSB_TK CSB_TK
 |      name OSB_TK CSB_TK
                {
-                 char *n = xmalloc (strlen ($1)+2);
-                 n [0] = '[';
-                 strcpy (n+1, $1);
-                 $$ = n;
+                 $$ = concat ("[", $1, NULL);
                }
 |      array_type OSB_TK CSB_TK
                {       
-                 char *n = xmalloc (strlen ($1)+2);
-                 n [0] = '[';
-                 strcpy (n+1, $1);
-                 $$ = n;
+                 $$ = concat ("[", $1, NULL);
                }
 ;
 
@@ -253,9 +252,7 @@ simple_name:
 qualified_name:
        name DOT_TK identifier
                { 
-                 char *n = xmalloc (strlen ($1)+strlen ($3)+2);
-                 sprintf (n, "%s.%s", $1, $3);
-                 $$ = n;
+                 $$ = concat ($1, ".", $3, NULL);
                }
 ;
 
@@ -451,9 +448,7 @@ formal_parameter_list:
        formal_parameter
 |      formal_parameter_list C_TK formal_parameter
                {
-                 char *n = xmalloc (strlen ($1)+strlen($3)+2);
-                 sprintf (n, "%s,%s", $1, $3);
-                 $$ = n;
+                 $$ = concat ($1, ",", $3, NULL);
                }
 ;
 
@@ -570,11 +565,13 @@ this_or_super:                    /* Added, simplifies error diagnostics */
 /* 19.9.1 Productions from 9.1: Interfaces Declarations  */
 interface_declaration:
        INTERFACE_TK identifier interface_body
+               { report_class_declaration ($2); modifier_value = 0; }
 |      modifiers INTERFACE_TK identifier interface_body
-               { modifier_value = 0; }
+               { report_class_declaration ($3); modifier_value = 0; }
 |      INTERFACE_TK identifier extends_interfaces interface_body
+               { report_class_declaration ($2); modifier_value = 0; }
 |      modifiers INTERFACE_TK identifier extends_interfaces interface_body
-               { modifier_value = 0; }
+               { report_class_declaration ($3); modifier_value = 0; }
 ;
 
 extends_interfaces:
@@ -1101,17 +1098,14 @@ constant_expression:
 
 %%
 \f
-#include "lex.c"
-
 /* Create a new parser context */
 
 void
 java_push_parser_context ()
 {
   struct parser_ctxt *new = 
-    (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
+    (struct parser_ctxt *) xcalloc (1, sizeof (struct parser_ctxt));
 
-  bzero (new, sizeof (struct parser_ctxt));
   new->next = ctxp;
   ctxp = new;
 }  
@@ -1120,7 +1114,7 @@ java_push_parser_context ()
 
 static void
 report_class_declaration (name)
-     char * name;
+     const char * name;
 {
   extern int flag_dump_class, flag_list_filename;
 
@@ -1178,17 +1172,6 @@ void reset_report ()
 
 void
 yyerror (msg)
-     char *msg;
-{
-}
-
-char *
-xstrdup (s)
-     const char *s;
+     const char *msg ATTRIBUTE_UNUSED;
 {
-  char *ret;
-
-  ret = xmalloc (strlen (s) + 1);
-  strcpy (ret, s);
-  return ret;
 }