This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

C Parser Cleanup


This is a small, simple patch that reaps some of the low-hanging fruit
in moving blocks of code out of c-parse.in to somewhere more
appropriate (and probably the first of many).

Bootstrapping and making check x86 Linux.

OK for mainline?

Neil.

	* c-delc.c (label_pointer): New function.
	* c-parse.in: Move 3 blocks of parser code into new functions.
	* c-typeck.c (simple_asm_stmt, c_cast_expr): New functions.
	* c-tree.h (label_pointer, simple_asm_stmt, c_cast_expr):
	New prototypes.

Index: gcc/c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.220
diff -u -p -r1.220 c-decl.c
--- c-decl.c	2001/05/01 12:11:31	1.220
+++ c-decl.c	2001/05/10 05:23:04
@@ -2692,6 +2692,27 @@ lookup_label (id)
   return decl;
 }
 
+/* Return the address of a LABEL as a pointer.  */
+tree
+label_pointer (name)
+     tree name;
+{
+  tree label, result;
+
+  if (pedantic)
+    pedwarn ("ISO C forbids `&&'");
+
+  label = lookup_label (name);
+  if (label == 0)
+    return null_pointer_node;
+
+  TREE_USED (label) = 1;
+  result = build1 (ADDR_EXPR, ptr_type_node, label);
+  TREE_CONSTANT (result) = 1;
+
+  return result;
+}
+
 /* Make a label named NAME in the current function,
    shadowing silently any that may be inherited from containing functions
    or containing scopes.
Index: gcc/c-parse.in
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-parse.in,v
retrieving revision 1.85
diff -u -p -r1.85 c-parse.in
--- c-parse.in	2001/04/24 08:22:04	1.85
+++ c-parse.in	2001/05/10 05:23:10
@@ -481,18 +481,7 @@ unary_expr:
 		  overflow_warning ($$); }
 	/* Refer to the address of a label as a pointer.  */
 	| ANDAND identifier
-		{ tree label = lookup_label ($2);
-		  if (pedantic)
-		    pedwarn ("ISO C forbids `&&'");
-		  if (label == 0)
-		    $$ = null_pointer_node;
-		  else
-		    {
-		      TREE_USED (label) = 1;
-		      $$ = build1 (ADDR_EXPR, ptr_type_node, label);
-		      TREE_CONSTANT ($$) = 1;
-		    }
-		}
+		{ $$ = label_pointer ($2); }
 /* This seems to be impossible on some machines, so let's turn it off.
    You can use __builtin_next_arg to find the anonymous stack args.
 	| '&' ELLIPSIS
@@ -540,15 +529,7 @@ alignof:
 cast_expr:
 	unary_expr
 	| '(' typename ')' cast_expr  %prec UNARY
-		{ tree type;
-		  int SAVED_warn_strict_prototypes = warn_strict_prototypes;
-		  /* This avoids warnings about unprototyped casts on
-                     integers.  E.g. "#define SIG_DFL (void(*)())0".  */
-		  if (TREE_CODE ($4) == INTEGER_CST)
-		    warn_strict_prototypes = 0;
-		  type = groktypename ($2);
-		  warn_strict_prototypes = SAVED_warn_strict_prototypes;
-		  $$ = build_c_cast (type, $4); }
+		{ $$ = c_cast_expr ($2, $4); }
 	;
 
 expr_no_commas:
@@ -1956,26 +1937,7 @@ stmt:
 		  $$ = c_expand_return ($2); }
 	| ASM_KEYWORD maybe_type_qual '(' expr ')' ';'
 		{ stmt_count++;
-		  STRIP_NOPS ($4);
-		  if ((TREE_CODE ($4) == ADDR_EXPR
-		       && TREE_CODE (TREE_OPERAND ($4, 0)) == STRING_CST)
-		      || TREE_CODE ($4) == STRING_CST)
-		    {
-		      if (TREE_CODE ($4) == ADDR_EXPR)
-			$4 = TREE_OPERAND ($4, 0);
-		      if (TREE_CHAIN ($4))
-			$4 = combine_strings ($4);
-		      $$ = add_stmt (build_stmt (ASM_STMT, NULL_TREE, $4,
-						 NULL_TREE, NULL_TREE,
-						 NULL_TREE));
-		      ASM_INPUT_P ($$) = 1;
-		    }
-		  else
-		    {
-		      error ("argument of `asm' is not a constant string");
-		      $$ = NULL_TREE;
-		    }
-		}
+		  $$ = simple_asm_stmt ($4); }
 	/* This is the case with just output operands.  */
 	| ASM_KEYWORD maybe_type_qual '(' expr ':' asm_operands ')' ';'
 		{ stmt_count++;
Index: gcc/c-tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-tree.h,v
retrieving revision 1.56
diff -u -p -r1.56 c-tree.h
--- c-tree.h	2001/04/12 18:23:09	1.56
+++ c-tree.h	2001/05/10 05:23:11
@@ -188,6 +188,7 @@ extern int  in_parm_level_p             
 extern void keep_next_level                     PARAMS ((void));
 extern int  kept_level_p                        PARAMS ((void));
 extern tree lookup_label                        PARAMS ((tree));
+extern tree label_pointer			PARAMS ((tree));
 extern tree lookup_name                         PARAMS ((tree));
 extern tree lookup_name_current_level		PARAMS ((tree));
 extern tree lookup_name_current_level_global	PARAMS ((tree));
@@ -233,7 +233,8 @@ extern tree parser_build_binary_op      
 extern void readonly_warning			PARAMS ((tree, const char *));
 extern tree build_conditional_expr              PARAMS ((tree, tree, tree));
 extern tree build_compound_expr                 PARAMS ((tree));
-extern tree build_c_cast                        PARAMS ((tree, tree));
+extern tree c_cast_expr				PARAMS ((tree, tree));
+extern tree build_c_cast	                PARAMS ((tree, tree));
 extern tree build_modify_expr                   PARAMS ((tree, enum tree_code,
 							 tree));
 extern void store_init_value                    PARAMS ((tree, tree));
@@ -251,6 +252,7 @@ extern void pedwarn_c99				PARAMS ((cons
 							ATTRIBUTE_PRINTF_1;
 extern tree c_start_case                        PARAMS ((tree));
 extern void c_finish_case                       PARAMS ((void));
+extern tree simple_asm_stmt			PARAMS ((tree));
 extern tree build_asm_stmt			PARAMS ((tree, tree, tree,
 							 tree, tree));
 
Index: gcc/c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.119
diff -u -p -r1.119 c-typeck.c
--- c-typeck.c	2001/05/06 16:38:56	1.119
+++ c-typeck.c	2001/05/10 05:23:29
@@ -3867,6 +3868,24 @@ build_c_cast (type, expr)
 
   return value;
 }
+
+/* Interpret a cast of expression EXPR to type TYPE.  */
+tree
+c_cast_expr (type, expr)
+     tree type, expr;
+{
+  int saved_wsp = warn_strict_prototypes;
+
+  /* This avoids warnings about unprototyped casts on
+     integers.  E.g. "#define SIG_DFL (void(*)())0".  */
+  if (TREE_CODE (expr) == INTEGER_CST)
+    warn_strict_prototypes = 0;
+  type = groktypename (type);
+  warn_strict_prototypes = saved_wsp;
+
+  return build_c_cast (type, expr);
+}
+
 
 /* Build an assignment expression of lvalue LHS from value RHS.
    MODIFYCODE is the code for a binary operator that we use
@@ -6763,6 +6782,34 @@ process_init_element (value)
   constructor_range_stack = 0;
 }
 
+/* Build an simple asm-statement, from a single expression.  */
+tree
+simple_asm_stmt (expr)
+     tree expr;
+{
+  STRIP_NOPS (expr);
+
+  if ((TREE_CODE (expr) == ADDR_EXPR
+       && TREE_CODE (TREE_OPERAND (expr, 0)) == STRING_CST)
+      || TREE_CODE (expr) == STRING_CST)
+    {
+      tree stmt;
+
+      if (TREE_CODE (expr) == ADDR_EXPR)
+	expr = TREE_OPERAND (expr, 0);
+      if (TREE_CHAIN (expr))
+	expr = combine_strings (expr);
+      stmt = add_stmt (build_stmt (ASM_STMT, NULL_TREE, expr,
+				   NULL_TREE, NULL_TREE,
+				   NULL_TREE));
+      ASM_INPUT_P (stmt) = 1;
+      return stmt;
+    }
+
+  error ("argument of `asm' is not a constant string");
+  return NULL_TREE;
+}
+
 /* Build an asm-statement, whose components are a CV_QUALIFIER, a
    STRING, some OUTPUTS, some INPUTS, and some CLOBBERS.  */
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]