A patch for more constification

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Fri Feb 19 13:01:00 GMT 1999


 > From: Jeffrey A Law <law@upchuck.cygnus.com>
 > 
 >   In message <199901241641.LAA22520@caip.rutgers.edu>you write:
 >   > 	Another constify patch.  Okay to install?
 >   > 
 >   > 		--Kaveh
 > 
 > This is OK.  Note that some of the changes will probably need to be
 > updated after the merge from gcc2.  Particularly the changes to error
 > message handling and the like.
 > jeff

	Right, done.  Below is the updated patch that I installed.

		--Kaveh

Index: ChangeLog
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/ChangeLog,v
retrieving revision 1.3022
diff -u -p -r1.3022 ChangeLog
--- ChangeLog	1999/02/18 19:49:14	1.3022
+++ ChangeLog	1999/02/19 04:30:46
@@ -1,3 +1,38 @@
+Thu Feb 18 23:28:35 1999  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
+
+        * bitmap.c (bitmap_print): Qualify a char* with the `const' keyword.
+	 
+        * bitmap.h (bitmap_print): Likewise.
+	 
+        * c-decl.c (builtin_function, grokdeclarator, grokfield): Likewise.
+	 
+        * c-lang.c (build_objc_string): Likewise.
+	 
+        * c-lex.c (yyerror, extend_token_buffer): Likewise.  Don't include
+ 	limits.h or ctype.h.  Remove unused variable `p'.
+	 
+        * c-lex.h (yyerror): Qualify a char* with the `const' keyword.
+	 
+        * c-pragma.c (handle_pragma_token): Likewise.
+	 
+        * c-pragma.h (handle_pragma_token): Likewise.
+	 
+        * c-tree.h (build_objc_string, builtin_function, grokfield,
+ 	build_indirect_ref, lvalue_or_else, readonly_warning, error_init,
+ 	pedwarn_init): Likewise.
+	 
+        * c-typeck.c (convert_for_assignment, warn_for_assignment,
+ 	push_string, warning_init, incomplete_type_error,
+ 	build_indirect_ref, lvalue_or_else, readonly_warning,
+ 	build_c_cast, spelling, push_member_name, print_spelling,
+ 	error_init, pedwarn_init, start_init): Likewise.
+	 
+        * objc/objc-act.c (build_objc_string): Likewise.
+	 
+        * print-tree.c (print_node_brief, print_node): Likewise.
+	 
+        * tree.h (lvalue_or_else, print_node, print_node_brief): Likewise.
+
 Thu Feb 18 20:44:21 1999  David Edelsohn  <edelsohn@mhpcc.edu>
 
 	* regclass.c (record_reg_classes): Correctly handle 'p' constraint.
Index: bitmap.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/bitmap.c,v
retrieving revision 1.12
diff -u -p -r1.12 bitmap.c
--- bitmap.c	1998/12/16 20:53:32	1.12
+++ bitmap.c	1999/02/19 04:30:46
@@ -613,10 +613,10 @@ void
 bitmap_print (file, head, prefix, suffix)
      FILE *file;
      bitmap head;
-     char *prefix;
-     char *suffix;
+     const char *prefix;
+     const char *suffix;
 {
-  char *comma = "";
+  const char *comma = "";
   int i;
 
   fputs (prefix, file);
Index: bitmap.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/bitmap.h,v
retrieving revision 1.10
diff -u -p -r1.10 bitmap.h
--- bitmap.h	1999/01/23 01:50:19	1.10
+++ bitmap.h	1999/02/19 04:30:47
@@ -89,7 +89,7 @@ extern void bitmap_debug PROTO((bitmap))
 extern void bitmap_debug_file PROTO((FILE *, bitmap));
 
 /* Print a bitmap */
-extern void bitmap_print PROTO((FILE *, bitmap, char *, char *));
+extern void bitmap_print PROTO((FILE *, bitmap, const char *, const char *));
 
 /* Initialize a bitmap header.  */
 extern bitmap bitmap_initialize PROTO((bitmap));
Index: c-decl.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-decl.c,v
retrieving revision 1.59
diff -u -p -r1.59 c-decl.c
--- c-decl.c	1999/01/31 17:46:15	1.59
+++ c-decl.c	1999/02/19 04:31:00
@@ -3616,10 +3616,10 @@ init_decl_processing ()
 
 tree
 builtin_function (name, type, function_code, library_name)
-     char *name;
+     const char *name;
      tree type;
      enum built_in_function function_code;
-     char *library_name;
+     const char *library_name;
 {
   tree decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
   DECL_EXTERNAL (decl) = 1;
@@ -4390,7 +4390,7 @@ grokdeclarator (declarator, declspecs, d
   int explicit_char = 0;
   int defaulted_int = 0;
   tree typedef_decl = 0;
-  char *name;
+  const char *name;
   tree typedef_type = 0;
   int funcdef_flag = 0;
   enum tree_code innermost_code = ERROR_MARK;
@@ -5770,8 +5770,8 @@ start_struct (code, name)
 
 tree
 grokfield (filename, line, declarator, declspecs, width)
-     char *filename;
-     int line;
+     const char *filename ATTRIBUTE_UNUSED;
+     int line ATTRIBUTE_UNUSED;
      tree declarator, declspecs, width;
 {
   tree value;
Index: c-lang.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lang.c,v
retrieving revision 1.17
diff -u -p -r1.17 c-lang.c
--- c-lang.c	1998/12/16 20:53:43	1.17
+++ c-lang.c	1999/02/19 04:31:00
@@ -149,7 +149,7 @@ recognize_objc_keyword ()
 tree
 build_objc_string (len, str)
     int len ATTRIBUTE_UNUSED;
-    char *str ATTRIBUTE_UNUSED;
+    const char *str ATTRIBUTE_UNUSED;
 {
   abort ();
   return NULL_TREE;
Index: c-lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lex.c,v
retrieving revision 1.44
diff -u -p -r1.44 c-lex.c
--- c-lex.c	1999/02/15 14:04:18	1.44
+++ c-lex.c	1999/02/19 04:31:05
@@ -22,10 +22,6 @@ Boston, MA 02111-1307, USA.  */
 #include "system.h"
 #include <setjmp.h>
 
-#if HAVE_LIMITS_H
-# include <limits.h>
-#endif
-
 #include "rtl.h"
 #include "tree.h"
 #include "input.h"
@@ -38,10 +34,6 @@ Boston, MA 02111-1307, USA.  */
 #include "toplev.h"
 #include "intl.h"
 
-#ifdef MAP_CHARACTER
-#include <ctype.h>
-#endif
-
 /* MULTIBYTE_CHARS support only works for native compilers.
    ??? Ideally what we want is to model widechar support after
    the current floating point support.  */
@@ -132,7 +124,7 @@ static int handle_generic_pragma	PROTO((
 static int whitespace_cr		PROTO((int));
 static int skip_white_space		PROTO((int));
 static int skip_white_space_on_line	PROTO((void));
-static char *extend_token_buffer	PROTO((char *));
+static char *extend_token_buffer	PROTO((const char *));
 static int readescape			PROTO((int *));
 
 /* Do not insert generated code into the source, instead, include it.
@@ -237,8 +229,6 @@ finish_parse ()
 void
 init_lex ()
 {
-  char *p;
-
   /* Make identifier nodes long enough for the language-specific slots.  */
   set_identifier_size (sizeof (struct lang_identifier));
 
@@ -494,7 +484,7 @@ skip_white_space_on_line ()
 
 static char *
 extend_token_buffer (p)
-     char *p;
+     const char *p;
 {
   int offset = p - token_buffer;
 
@@ -1059,9 +1049,9 @@ readescape (ignore_ptr)
 
 void
 yyerror (msgid)
-     char *msgid;
+     const char *msgid;
 {
-  char *string = _(msgid);
+  const char *string = _(msgid);
 
   /* We can't print string and character constants well
      because the token_buffer contains the result of processing escapes.  */
Index: c-lex.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lex.h,v
retrieving revision 1.10
diff -u -p -r1.10 c-lex.h
--- c-lex.h	1999/01/06 20:44:03	1.10
+++ c-lex.h	1999/02/19 04:31:05
@@ -81,7 +81,7 @@ extern void position_after_white_space P
 extern int check_newline PROTO((void));
 
 extern int yylex PROTO((void));
-extern void yyerror PROTO((char *));
+extern void yyerror PROTO((const char *));
 
 extern void forget_protocol_qualifiers PROTO((void));
 extern void remember_protocol_qualifiers PROTO((void));
Index: c-pragma.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-pragma.c,v
retrieving revision 1.13
diff -u -p -r1.13 c-pragma.c
--- c-pragma.c	1998/12/16 20:53:54	1.13
+++ c-pragma.c	1999/02/19 04:31:06
@@ -231,7 +231,7 @@ add_weak (name, value)
 
 int
 handle_pragma_token (string, token)
-     char * string;
+     const char * string;
      tree token;
 {
   static enum pragma_state state = ps_start;
Index: c-pragma.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-pragma.h,v
retrieving revision 1.6
diff -u -p -r1.6 c-pragma.h
--- c-pragma.h	1998/12/16 20:53:55	1.6
+++ c-pragma.h	1999/02/19 04:31:06
@@ -94,7 +94,7 @@ enum pragma_state
 };
 
 /* Handle a C style pragma */
-extern int handle_pragma_token PROTO((char *, tree));
+extern int handle_pragma_token PROTO((const char *, tree));
 
 #endif /* HANDLE_GENERIC_PRAGMAS */
 #endif /* _C_PRAGMA_H */
Index: c-tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-tree.h,v
retrieving revision 1.19
diff -u -p -r1.19 c-tree.h
--- c-tree.h	1999/01/31 17:46:17	1.19
+++ c-tree.h	1999/02/19 04:31:07
@@ -170,7 +170,7 @@ extern int maybe_objc_comptypes         
 extern tree maybe_building_objc_message_expr    PROTO((void));
 extern tree maybe_objc_method_name		PROTO((tree));
 extern int recognize_objc_keyword		PROTO((void));
-extern tree build_objc_string			PROTO((int, char *));
+extern tree build_objc_string			PROTO((int, const char *));
 
 /* in c-aux-info.c */
 extern void gen_aux_info_record                 PROTO((tree, int, int, int));
@@ -282,7 +282,7 @@ extern tree boolean_false_node;
 
 extern tree build_enumerator                    PROTO((tree, tree));
 /* Declare a predefined function.  Return the declaration.  */
-extern tree builtin_function                    PROTO((char *, tree, enum built_in_function function_, char *));
+extern tree builtin_function                    PROTO((const char *, tree, enum built_in_function function_, const char *));
 /* Add qualifiers to a type, in the fashion for C.  */
 extern tree c_build_qualified_type              PROTO((tree, int));
 #define c_build_type_variant(TYPE, CONST_P, VOLATILE_P)		  \
@@ -307,7 +307,7 @@ extern tree get_parm_info               
 extern tree getdecls                            PROTO((void));
 extern tree gettags                             PROTO((void));
 extern int  global_bindings_p                   PROTO((void));
-extern tree grokfield                           PROTO((char *, int, tree, tree, tree));
+extern tree grokfield                           PROTO((const char *, int, tree, tree, tree));
 extern tree groktypename                        PROTO((tree));
 extern tree groktypename_in_parm_context        PROTO((tree));
 extern tree implicitly_declare                  PROTO((tree));
@@ -365,7 +365,7 @@ extern tree c_alignof				PROTO((tree));
 extern tree c_alignof_expr			PROTO((tree));
 extern tree default_conversion                  PROTO((tree));
 extern tree build_component_ref                 PROTO((tree, tree));
-extern tree build_indirect_ref                  PROTO((tree, char *));
+extern tree build_indirect_ref                  PROTO((tree, const char *));
 extern tree build_array_ref                     PROTO((tree, tree));
 extern tree build_function_call                 PROTO((tree, tree));
 extern tree parser_build_binary_op              PROTO((enum tree_code,
@@ -375,8 +375,8 @@ extern tree build_binary_op             
 extern tree build_unary_op                      PROTO((enum tree_code,
 						       tree, int));
 extern int lvalue_p				PROTO((tree));
-extern int lvalue_or_else			PROTO((tree, char *));
-extern void readonly_warning			PROTO((tree, char *));
+extern int lvalue_or_else			PROTO((tree, const char *));
+extern void readonly_warning			PROTO((tree, const char *));
 extern int mark_addressable			PROTO((tree));
 extern tree build_conditional_expr              PROTO((tree, tree, tree));
 extern tree build_compound_expr                 PROTO((tree));
@@ -385,8 +385,8 @@ extern tree build_modify_expr           
 						       tree));
 extern tree initializer_constant_valid_p	PROTO((tree, tree));
 extern void store_init_value                    PROTO((tree, tree));
-extern void error_init				PROTO((char *));
-extern void pedwarn_init			PROTO((char *));
+extern void error_init				PROTO((const char *));
+extern void pedwarn_init			PROTO((const char *));
 extern void start_init				PROTO((tree, tree, int));
 extern void finish_init				PROTO((void));
 extern void really_start_incremental_init	PROTO((tree));
Index: c-typeck.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-typeck.c,v
retrieving revision 1.24
diff -u -p -r1.24 c-typeck.c
--- c-typeck.c	1999/02/08 16:00:45	1.24
+++ c-typeck.c	1999/02/19 04:31:17
@@ -56,16 +56,17 @@ static tree pointer_diff		PROTO((tree, t
 static tree unary_complex_lvalue	PROTO((enum tree_code, tree));
 static void pedantic_lvalue_warning	PROTO((enum tree_code));
 static tree internal_build_compound_expr PROTO((tree, int));
-static tree convert_for_assignment	PROTO((tree, tree, char *, tree,
+static tree convert_for_assignment	PROTO((tree, tree, const char *, tree,
 					       tree, int));
-static void warn_for_assignment		PROTO((char *, char *, tree, int));
+static void warn_for_assignment		PROTO((const char *, const char *,
+					       tree, int));
 static tree valid_compound_expr_initializer PROTO((tree, tree));
-static void push_string			PROTO((char *));
+static void push_string			PROTO((const char *));
 static void push_member_name		PROTO((tree));
 static void push_array_bounds		PROTO((int));
 static int spelling_length		PROTO((void));
 static char *print_spelling		PROTO((char *));
-static void warning_init		PROTO((char *));
+static void warning_init		PROTO((const char *));
 static tree digest_init			PROTO((tree, tree, int, int));
 static void check_init_type_bitfields	PROTO((tree));
 static void output_init_element		PROTO((tree, tree, tree, int));
@@ -100,7 +101,7 @@ incomplete_type_error (value, type)
      tree value;
      tree type;
 {
-  char *type_code_string;
+  const char *type_code_string;
 
   /* Avoid duplicate error message.  */
   if (TREE_CODE (type) == ERROR_MARK)
@@ -1321,7 +1322,7 @@ build_component_ref (datum, component)
 tree
 build_indirect_ref (ptr, errorstring)
      tree ptr;
-     char *errorstring;
+     const char *errorstring;
 {
   register tree pointer = default_conversion (ptr);
   register tree type = TREE_TYPE (pointer);
@@ -3231,7 +3232,7 @@ lvalue_p (ref)
 int
 lvalue_or_else (ref, msgid)
      tree ref;
-     char *msgid;
+     const char *msgid;
 {
   int win = lvalue_p (ref);
   if (! win)
@@ -3300,7 +3301,7 @@ pedantic_lvalue_warning (code)
 void
 readonly_warning (arg, msgid)
      tree arg;
-     char *msgid;
+     const char *msgid;
 {
   /* Forbid assignments to iterators.  */
   if (TREE_CODE (arg) == VAR_DECL && ITERATOR_P (arg))
@@ -3723,7 +3724,7 @@ build_c_cast (type, expr)
 
       if (field)
 	{
-	  char *name;
+	  const char *name;
 	  tree t;
 
 	  if (pedantic)
@@ -4029,7 +4030,7 @@ build_modify_expr (lhs, modifycode, rhs)
 static tree
 convert_for_assignment (type, rhs, errtype, fundecl, funname, parmnum)
      tree type, rhs;
-     char *errtype;
+     const char *errtype;
      tree fundecl, funname;
      int parmnum;
 {
@@ -4288,14 +4289,15 @@ convert_for_assignment (type, rhs, errty
 
 static void
 warn_for_assignment (msgid, opname, function, argnum)
-     char *msgid;
-     char *opname;
+     const char *msgid;
+     const char *opname;
      tree function;
      int argnum;
 {
   if (opname == 0)
     {
       tree selector = maybe_building_objc_message_expr ();
+      char * new_opname;
       
       if (selector && argnum > 2)
 	{
@@ -4305,18 +4307,21 @@ warn_for_assignment (msgid, opname, func
       if (function)
 	{
 	  /* Function name is known; supply it.  */
-	  char *argstring = _("passing arg %d of `%s'");
-	  opname = (char *) alloca (IDENTIFIER_LENGTH (function)
-				    + strlen (argstring) + 1 + 25 /*%d*/ + 1);
-	  sprintf (opname, argstring, argnum, IDENTIFIER_POINTER (function));
+	  const char *argstring = _("passing arg %d of `%s'");
+	  new_opname = (char *) alloca (IDENTIFIER_LENGTH (function)
+					+ strlen (argstring) + 1 + 25
+					/*%d*/ + 1);
+	  sprintf (new_opname, argstring, argnum,
+		   IDENTIFIER_POINTER (function));
 	}
       else
 	{
-	  /* Function name unknown (call through ptr); just give arg number.  */
-	  char *argnofun = _("passing arg %d of pointer to function");
-	  opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
-	  sprintf (opname, argnofun, argnum);
+	  /* Function name unknown (call through ptr); just give arg number.*/
+	  const char *argnofun = _("passing arg %d of pointer to function");
+	  new_opname = (char *) alloca (strlen (argnofun) + 1 + 25 /*%d*/ + 1);
+	  sprintf (new_opname, argnofun, argnum);
 	}
+      opname = new_opname;
     }
   pedwarn (msgid, opname);
 }
@@ -4557,7 +4562,7 @@ struct spelling
   union
     {
       int i;
-      char *s;
+      const char *s;
     } u;
 };
 
@@ -4613,7 +4618,7 @@ static int spelling_size;		/* Size of th
 
 static void
 push_string (string)
-     char *string;
+     const char *string;
 {
   PUSH_SPELLING (SPELLING_STRING, string, u.s);
 }
@@ -4625,7 +4630,7 @@ push_member_name (decl)
      tree decl;
      
 {
-  char *string
+  const char *string
     = DECL_NAME (decl) ? IDENTIFIER_POINTER (DECL_NAME (decl)) : "<anonymous>";
   PUSH_SPELLING (SPELLING_MEMBER, string, u.s);
 }
@@ -4665,7 +4670,6 @@ print_spelling (buffer)
      register char *buffer;
 {
   register char *d = buffer;
-  register char *s;
   register struct spelling *p;
 
   for (p = spelling_base; p < spelling; p++)
@@ -4676,6 +4680,7 @@ print_spelling (buffer)
       }
     else
       {
+	register const char *s;
 	if (p->kind == SPELLING_MEMBER)
 	  *d++ = '.';
 	for (s = p->u.s; (*d = *s++); d++)
@@ -4691,7 +4696,7 @@ print_spelling (buffer)
 
 void
 error_init (msgid)
-     char *msgid;
+     const char *msgid;
 {
   char *ofwhat;
 
@@ -4707,7 +4712,7 @@ error_init (msgid)
 
 void
 pedwarn_init (msgid)
-     char *msgid;
+     const char *msgid;
 {
   char *ofwhat;
 
@@ -4723,7 +4728,7 @@ pedwarn_init (msgid)
 
 static void
 warning_init (msgid)
-     char *msgid;
+     const char *msgid;
 {
   char *ofwhat;
 
@@ -5103,7 +5108,7 @@ start_init (decl, asmspec_tree, top_leve
      tree asmspec_tree;
      int top_level;
 {
-  char *locus;
+  const char *locus;
   struct initializer_stack *p
     = (struct initializer_stack *) xmalloc (sizeof (struct initializer_stack));
   char *asmspec = 0;
Index: print-tree.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/print-tree.c,v
retrieving revision 1.13
diff -u -p -r1.13 print-tree.c
--- print-tree.c	1999/01/06 20:51:09	1.13
+++ print-tree.c	1999/02/19 04:31:18
@@ -64,7 +64,7 @@ debug_tree (node)
 void
 print_node_brief (file, prefix, node, indent)
      FILE *file;
-     char *prefix;
+     const char *prefix;
      tree node;
      int indent;
 {
@@ -176,7 +176,7 @@ indent_to (file, column)
 void
 print_node (file, prefix, node, indent)
      FILE *file;
-     char *prefix;
+     const char *prefix;
      tree node;
      int indent;
 {
Index: tree.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tree.h,v
retrieving revision 1.68
diff -u -p -r1.68 tree.h
--- tree.h	1999/02/17 08:04:29	1.68
+++ tree.h	1999/02/19 04:31:21
@@ -1672,7 +1672,7 @@ extern int staticp			PROTO((tree));
 /* Gets an error if argument X is not an lvalue.
    Also returns 1 if X is an lvalue, 0 if not.  */
 
-extern int lvalue_or_else		PROTO((tree, char *));
+extern int lvalue_or_else		PROTO((tree, const char *));
 
 /* save_expr (EXP) returns an expression equivalent to EXP
    but it can be used multiple times within context CTX
@@ -2209,8 +2209,8 @@ extern void print_rtl			PROTO ((FILE *, 
 /* In print-tree.c */
 extern void debug_tree			PROTO ((tree));
 #ifdef BUFSIZ
-extern void print_node			PROTO ((FILE *, char *, tree, int));
-extern void print_node_brief		PROTO ((FILE *, char *, tree, int));
+extern void print_node			PROTO ((FILE *, const char *, tree, int));
+extern void print_node_brief		PROTO ((FILE *, const char *, tree, int));
 extern void indent_to			PROTO ((FILE *, int));
 #endif
 
Index: objc/objc-act.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/objc/objc-act.c,v
retrieving revision 1.23
diff -u -p -r1.23 objc-act.c
--- objc-act.c	1999/02/16 15:39:00	1.23
+++ objc-act.c	1999/02/19 04:31:31
@@ -1320,7 +1320,7 @@ my_build_string (len, str)
 tree
 build_objc_string (len, str)
      int len;
-     char *str;
+     const char *str;
 {
   tree s = build_string (len, str);
 


More information about the Gcc-patches mailing list