[PATCH] Fix PR c/11658

Bonzini bonzini@gnu.org
Mon Feb 2 14:01:00 GMT 2004


This adds a C/ObjectiveC langhook and uses it throughout
c-parse.in.

Paolo

2004-02-02  Paolo Bonzini  <bonzini@gnu.org>

	PR c/11658
	* Makefile.in (c-parse.o): Depend on langhooks.h.
	* c-parse.in: Include langhooks.h, use
	truthvalue_conversion language hook.
	* c-common.c (c_common_truthvalue_conversion): Remove
	obsolete block.
	* c-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Use
	c_objc_common_truthvalue_conversion.
	* c-objc-common.c (c_objc_common_truthvalue_conversion):
	New function.
	* c-tree.h (c_objc_common_truthvalue_conversion): Declare it.
	* objc/Make-lang.in (objc-parse.o): Depend on langhooks.h.
	* objc/objc-lang.c (LANG_HOOKS_TRUTHVALUE_CONVERSION): Use
	c_objc_common_truthvalue_conversion.

Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Makefile.in,v
retrieving revision 1.1240
diff -u -r1.1240 Makefile.in
--- Makefile.in	2 Feb 2004 00:17:08 -0000	1.1240
+++ Makefile.in	2 Feb 2004 13:49:30 -0000
@@ -1272,7 +1272,7 @@
     $(C_TREE_H) flags.h $(DIAGNOSTIC_H) $(TM_P_H)
 c-parse.o : c-parse.c $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) \
     $(GGC_H) intl.h $(C_TREE_H) input.h flags.h toplev.h output.h $(CPPLIB_H) \
-    varray.h gt-c-parse.h
+    varray.h gt-c-parse.h langhooks.h
 
 srcextra: c-parse.y c-parse.c gengtype-lex.c gengtype-yacc.c gengtype-yacc.h
 	-cp -p $^ $(srcdir)
Index: c-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.c,v
retrieving revision 1.479
diff -u -r1.479 c-common.c
--- c-common.c	21 Jan 2004 20:39:51 -0000	1.479
+++ c-common.c	2 Feb 2004 13:49:31 -0000
@@ -2614,28 +2614,6 @@
   if (TREE_CODE (expr) == FUNCTION_DECL)
     expr = build_unary_op (ADDR_EXPR, expr, 0);
 
-#if 0 /* This appears to be wrong for C++.  */
-  /* These really should return error_mark_node after 2.4 is stable.
-     But not all callers handle ERROR_MARK properly.  */
-  switch (TREE_CODE (TREE_TYPE (expr)))
-    {
-    case RECORD_TYPE:
-      error ("struct type value used where scalar is required");
-      return truthvalue_false_node;
-
-    case UNION_TYPE:
-      error ("union type value used where scalar is required");
-      return truthvalue_false_node;
-
-    case ARRAY_TYPE:
-      error ("array type value used where scalar is required");
-      return truthvalue_false_node;
-
-    default:
-      break;
-    }
-#endif /* 0 */
-
   switch (TREE_CODE (expr))
     {
     case EQ_EXPR:
Index: c-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-lang.c,v
retrieving revision 1.119
diff -u -r1.119 c-lang.c
--- c-lang.c	25 Sep 2003 01:25:46 -0000	1.119
+++ c-lang.c	2 Feb 2004 13:49:31 -0000
@@ -66,7 +66,7 @@
 #undef LANG_HOOKS_PARSE_FILE
 #define LANG_HOOKS_PARSE_FILE c_common_parse_file
 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
-#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
+#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_objc_common_truthvalue_conversion
 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL
Index: c-objc-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-objc-common.c,v
retrieving revision 1.37
diff -u -r1.37 c-objc-common.c
--- c-objc-common.c	1 Jan 2004 13:58:56 -0000	1.37
+++ c-objc-common.c	2 Feb 2004 13:49:31 -0000
@@ -332,3 +332,24 @@
   pp_string (pp, n);
   return true;
 }
+
+tree
+c_objc_common_truthvalue_conversion (tree expr)
+{
+  switch (TREE_CODE (TREE_TYPE (expr)))
+    {
+    case RECORD_TYPE:
+      error ("struct type value used where scalar is required");
+      return error_mark_node;
+
+    case UNION_TYPE:
+      error ("union type value used where scalar is required");
+      return error_mark_node;
+
+    default:
+      break;
+    }
+
+  return c_common_truthvalue_conversion (expr);
+}
+
Index: c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.196
diff -u -r1.196 c-parse.in
--- c-parse.in	26 Jan 2004 23:02:04 -0000	1.196
+++ c-parse.in	2 Feb 2004 13:49:31 -0000
@@ -38,6 +38,7 @@
 #include "coretypes.h"
 #include "tm.h"
 #include "tree.h"
+#include "langhooks.h"
 #include "input.h"
 #include "cpplib.h"
 #include "intl.h"
@@ -579,21 +580,21 @@
 	| expr_no_commas '^' expr_no_commas
 		{ $$ = parser_build_binary_op ($2, $1, $3); }
 	| expr_no_commas ANDAND
-		{ $1 = c_common_truthvalue_conversion
+		{ $1 = (*lang_hooks.truthvalue_conversion)
 		    (default_conversion ($1));
 		  skip_evaluation += $1 == truthvalue_false_node; }
 	  expr_no_commas
 		{ skip_evaluation -= $1 == truthvalue_false_node;
 		  $$ = parser_build_binary_op (TRUTH_ANDIF_EXPR, $1, $4); }
 	| expr_no_commas OROR
-		{ $1 = c_common_truthvalue_conversion
+		{ $1 = (*lang_hooks.truthvalue_conversion)
 		    (default_conversion ($1));
 		  skip_evaluation += $1 == truthvalue_true_node; }
 	  expr_no_commas
 		{ skip_evaluation -= $1 == truthvalue_true_node;
 		  $$ = parser_build_binary_op (TRUTH_ORIF_EXPR, $1, $4); }
 	| expr_no_commas '?'
-		{ $1 = c_common_truthvalue_conversion
+		{ $1 = (*lang_hooks.truthvalue_conversion)
 		    (default_conversion ($1));
 		  skip_evaluation += $1 == truthvalue_false_node; }
           expr ':'
@@ -607,7 +608,7 @@
 		    pedwarn ("ISO C forbids omitting the middle term of a ?: expression");
 		  /* Make sure first operand is calculated only once.  */
 		  $<ttype>2 = save_expr ($1);
-		  $1 = c_common_truthvalue_conversion
+		  $1 = (*lang_hooks.truthvalue_conversion)
 		    (default_conversion ($<ttype>2));
 		  skip_evaluation += $1 == truthvalue_true_node; }
 	  ':' expr_no_commas
@@ -2192,7 +2193,7 @@
           IF
                 { $<ttype>$ = c_begin_if_stmt (); }
             '(' expr ')'
-		{ c_expand_start_cond (c_common_truthvalue_conversion ($4),
+		{ c_expand_start_cond ((*lang_hooks.truthvalue_conversion) ($4),
 				       compstmt_count,$<ttype>2);
 		  $<itype>$ = stmt_count;
 		  if_stmt_locus = $<location>-1; }
@@ -2301,16 +2302,16 @@
 		  $<ttype>$ = c_begin_while_stmt (); }
 	  '(' expr ')'
                 { c_in_iteration_stmt++;
-		  $4 = c_common_truthvalue_conversion ($4);
+		  $4 = (*lang_hooks.truthvalue_conversion) ($4);
 		  c_finish_while_stmt_cond
-		    (c_common_truthvalue_conversion ($4), $<ttype>2);
+		    ((*lang_hooks.truthvalue_conversion) ($4), $<ttype>2);
 		  $<ttype>$ = add_stmt ($<ttype>2); }
 	  c99_block_lineno_labeled_stmt
                 { c_in_iteration_stmt--;
 		  RECHAIN_STMTS ($<ttype>6, WHILE_BODY ($<ttype>6)); }
 	| do_stmt_start
 	  '(' expr ')' ';'
-                { DO_COND ($1) = c_common_truthvalue_conversion ($3); }
+                { DO_COND ($1) = (*lang_hooks.truthvalue_conversion) ($3); }
 	| do_stmt_start error
 		{ }
 	| FOR
@@ -2323,7 +2324,7 @@
 	  xexpr ';'
                 { if ($6)
 		    FOR_COND ($<ttype>2)
-		      = c_common_truthvalue_conversion ($6); }
+		      = (*lang_hooks.truthvalue_conversion) ($6); }
 	  xexpr ')'
                 { c_in_iteration_stmt++;
 		  FOR_EXPR ($<ttype>2) = $9; }
Index: c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.136
diff -u -r1.136 c-tree.h
--- c-tree.h	3 Dec 2003 23:33:48 -0000	1.136
+++ c-tree.h	2 Feb 2004 13:49:31 -0000
@@ -237,6 +237,7 @@
 extern int c_disregard_inline_limits (tree);
 extern int c_cannot_inline_tree_fn (tree *);
 extern bool c_objc_common_init (void);
+extern tree c_objc_common_truthvalue_conversion (tree expr);
 extern int c_missing_noreturn_ok_p (tree);
 extern void c_objc_common_finish_file (void);
 extern int defer_fn (tree);
Index: objc/Make-lang.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/Make-lang.in,v
retrieving revision 1.69
diff -u -r1.69 Make-lang.in
--- objc/Make-lang.in	21 Jan 2004 02:01:55 -0000	1.69
+++ objc/Make-lang.in	2 Feb 2004 13:49:31 -0000
@@ -64,7 +64,8 @@
 
 objc/objc-parse.o : objc/objc-parse.c \
    $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(C_TREE_H) \
-   toplev.h $(GGC_H) c-pragma.h input.h flags.h output.h objc/objc-act.h
+   toplev.h $(GGC_H) c-pragma.h input.h flags.h output.h objc/objc-act.h \
+   langhooks.h
 
 objc/objc-act.o : objc/objc-act.c \
    $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(RTL_H) $(TM_P_H) \
Index: objc/objc-lang.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/objc/objc-lang.c,v
retrieving revision 1.39
diff -u -r1.39 objc-lang.c
--- objc/objc-lang.c	29 Aug 2003 23:21:13 -0000	1.39
+++ objc/objc-lang.c	2 Feb 2004 13:49:31 -0000
@@ -60,7 +60,7 @@
 #undef LANG_HOOKS_MARK_ADDRESSABLE
 #define LANG_HOOKS_MARK_ADDRESSABLE c_mark_addressable
 #undef LANG_HOOKS_TRUTHVALUE_CONVERSION
-#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_common_truthvalue_conversion
+#define LANG_HOOKS_TRUTHVALUE_CONVERSION c_objc_common_truthvalue_conversion
 #undef LANG_HOOKS_FINISH_INCOMPLETE_DECL
 #define LANG_HOOKS_FINISH_INCOMPLETE_DECL c_finish_incomplete_decl
 #undef LANG_HOOKS_UNSAFE_FOR_REEVAL



More information about the Gcc-patches mailing list