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]

Proposed patch to tidy up HANDLE_PRAGMA and HANDLE_SYSV_PRAGMA


Hi,

  I would like to submit the enclosed patch which tidies up the
workings of the HANDLE_PRAGMA macro and the HANDLE_SYSV_PRAGMA
define.  The patch:

  * Allows HANDLE_PRAGMA to be called before handle_sysv_pragma() so
    that backends can interpret sysV style pragmas if they want to.

  * Allows HANDLE_PRAGMA to be used even if USE_CPPLIB is defined.
    (This currently only works for builds of the C and C++ front
    ends).

  * Makes handle_sysv_pragma() behave in the same way as
    HANDLE_PRAGMA, so simplifying the code in c-lex.c

  * Allows warnings for unrecognised pragmas to be generated even if
    HANDLE_SYSV_PRAGMA is not defined.

  * Only creates the handle_pragma_weak() function in varasm.c if
    HANDLE_PRAGMA_WEAK is defined (by c-pragma.h).

Cheers
	Nick



Fri Aug  7 17:25:29 1998  Nick Clifton  <nickc@cygnus.com>

	* c-lex.c (check_newline):  Call HANDLE_PRAGMA before
	HANDLE_SYSV_PRAGMA if both are defined.  Generate warning messages
	if unknown pragmas are encountered.
	(handle_sysv_pragma): Interpret return code from
	handle_pragma_token ().  Return success/failure indication rather
	than next unprocessed character. 
	
	* c-pragma.c (handle_pragma_token): Return success/failure status
	of the parse.
	
	* c-pragma.h: Change prototype of handle_pragma_token().

	* varasm.c: (handle_pragma_weak): Only create this function if
	HANDLE_PRAGMA_WEAK is defined.
	
	* tm.texi (HANDLE_PRAGMA): Document the use of HANDLE_PRAGMA when
	USE_CPPLIB is enabled.


Index: c-lex.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-lex.c,v
retrieving revision 1.28
diff -w -p -r1.28 c-lex.c
*** c-lex.c	1998/07/27 12:51:56	1.28
--- c-lex.c	1998/08/11 00:12:41
*************** check_newline ()
*** 530,563 ****
  		c = GETC ();
  	      if (c == '\n')
  		return c;
! #ifdef HANDLE_SYSV_PRAGMA
  	      UNGETC (c);
  	      token = yylex ();
  	      if (token != IDENTIFIER)
  		goto skipline;
! 	      return handle_sysv_pragma (token);
! #else /* !HANDLE_SYSV_PRAGMA */
  #ifdef HANDLE_PRAGMA
  #if !USE_CPPLIB
- 	      UNGETC (c);
- 	      token = yylex ();
- 	      if (token != IDENTIFIER)
- 		goto skipline;
  	      if (nextchar >= 0)
- 		c = nextchar, nextchar = -1;
- 	      else
- 		c = GETC ();
- 	      ungetc (c, finput);
- 	      if (HANDLE_PRAGMA (finput, yylval.ttype))
  		{
! 		  c = GETC ();
! 		  return c;
  		}
  #else
! 	      ??? do not know what to do ???;
! #endif /* !USE_CPPLIB */
  #endif /* HANDLE_PRAGMA */
  #endif /* !HANDLE_SYSV_PRAGMA */
  	      goto skipline;
  	    }
  	}
--- 530,574 ----
  		c = GETC ();
  	      if (c == '\n')
  		return c;
! 
! #if defined HANDLE_PRAGMA || defined HANDLE_SYSV_PRAGMA	      
  	      UNGETC (c);
  	      token = yylex ();
  	      if (token != IDENTIFIER)
  		goto skipline;
! 	      
  #ifdef HANDLE_PRAGMA
+ 	      /* We invoke HANDLE_PRAGMA before HANDLE_SYSV_PRAGMA
+ 		 (if both are defined), in order to give the back
+ 		 end a chance to override the interpretation of
+ 		 SYSV style pragmas.  */
  #if !USE_CPPLIB
  	      if (nextchar >= 0)
  		{
! 		  c = nextchar, nextchar = -1;
! 		  UNGETC (c);
  		}
+ 	      if (HANDLE_PRAGMA (finput, yylval.ttype))
+ 		return GETC ();
  #else	      
! 	      if (HANDLE_PRAGMA (NULL, yylval.ttype))
! 		return GETC ();
! #endif /* USE_CPPLIB */
  #endif /* HANDLE_PRAGMA */
+ 	      
+ #ifdef HANDLE_SYSV_PRAGMA
+ 	      if (handle_sysv_pragma (token))
+ 		return GETC ();
  #endif /* !HANDLE_SYSV_PRAGMA */
+ #endif /* HANDLE_PRAGMA || HANDLE_SYSV_PRAGMA */
+ 	      
+ 	      /* Issue a warning message if we have been asked to do so.
+ 		 Ignoring unknown pragmas in system header file unless
+ 		 an explcit -Wunknown-pragmas has been given. */
+ 	      if (warn_unknown_pragmas > 1
+ 		  || (warn_unknown_pragmas && ! in_system_header))
+ 		warning ("ignoring pragma: %s", token_buffer);
+ 	      
  	      goto skipline;
  	    }
  	}
*************** handle_sysv_pragma (token)
*** 842,848 ****
  	  handle_pragma_token (token_buffer, yylval.ttype);
  	  break;
  	default:
! 	  handle_pragma_token (token_buffer, 0);
  	}
  #if !USE_CPPLIB
        if (nextchar >= 0)
--- 853,859 ----
  	  handle_pragma_token (token_buffer, yylval.ttype);
  	  break;
  	default:
! 	  handle_pragma_token (token_buffer, NULL);
  	}
  #if !USE_CPPLIB
        if (nextchar >= 0)
*************** handle_sysv_pragma (token)
*** 853,864 ****
  
        while (c == ' ' || c == '\t')
  	c = GETC ();
-       if (c == '\n' || c == EOF)
- 	{
- 	  handle_pragma_token (0, 0);
- 	  return c;
- 	}
        UNGETC (c);
        token = yylex ();
      }
  }
--- 864,874 ----
  
        while (c == ' ' || c == '\t')
  	c = GETC ();
        UNGETC (c);
+       
+       if (c == '\n' || c == EOF)
+ 	return handle_pragma_token (NULL, NULL);
+ 
        token = yylex ();
      }
  }


Index: c-pragma.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-pragma.c,v
retrieving revision 1.7
diff -w -p -r1.7 c-pragma.c
*** c-pragma.c	1998/05/28 06:47:21	1.7
--- c-pragma.c	1998/08/11 00:12:52
***************
*** 1,5 ****
  /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
!    Copyright (C) 1992, 1997 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
--- 1,5 ----
  /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
!    Copyright (C) 1992, 1997, 1998 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
*************** Boston, MA 02111-1307, USA.  */
*** 37,49 ****
  
  extern int maximum_field_alignment;
  
- /* File used for outputting assembler code.  */
- extern FILE *asm_out_file;
- 
  /* Handle one token of a pragma directive.  TOKEN is the
!    current token, and STRING is its printable form.  */
  
! void
  handle_pragma_token (string, token)
       char *string;
       tree token;
--- 37,48 ----
  
  extern int maximum_field_alignment;
  
  /* Handle one token of a pragma directive.  TOKEN is the
!    current token, and STRING is its printable form. 
!    Return zero if an entire pragma was parsed, but it was
!    flawed in some way.  Return non-zero in all other cases.  */
  
! int
  handle_pragma_token (string, token)
       char *string;
       tree token;
*************** handle_pragma_token (string, token)
*** 53,78 ****
    static char *value;
    static int align;
  
!   if (string == 0)
      {
        if (type == ps_pack)
  	{
  	  if (state == ps_right)
  	    maximum_field_alignment = align * 8;
  	  else
  	    warning ("malformed `#pragma pack'");
  	}
        else if (type == ps_weak)
  	{
  #ifdef HANDLE_PRAGMA_WEAK
  	  if (HANDLE_PRAGMA_WEAK)
  	    handle_pragma_weak (state, name, value);
- 
  #endif /* HANDLE_PRAGMA_WEAK */
  	}
  
        type = state = ps_start;
!       return;
      }
  
    switch (state)
--- 52,84 ----
    static char *value;
    static int align;
  
!   if (string == NULL)
      {
+       int ret_val = 1;
+       
        if (type == ps_pack)
  	{
  	  if (state == ps_right)
  	    maximum_field_alignment = align * 8;
  	  else
+ 	    {
  	      warning ("malformed `#pragma pack'");
+ 	      ret_val = 0;
  	    }
+ 	}
+       else if (type == ps_bad)
+ 	ret_val = 0;
        else if (type == ps_weak)
  	{
  #ifdef HANDLE_PRAGMA_WEAK
  	  if (HANDLE_PRAGMA_WEAK)
  	    handle_pragma_weak (state, name, value);
  #endif /* HANDLE_PRAGMA_WEAK */
  	}
  
        type = state = ps_start;
!       
!       return ret_val;
      }
  
    switch (state)
*************** handle_pragma_token (string, token)
*** 82,105 ****
  	{
  	  if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0)
  	    type = state = ps_pack;
  	  else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
  	    type = state = ps_weak;
  	  else
- 	    {
  	      type = state = ps_done;
- 
- 	      /* Issue a warning message if we have been asked to do so.
- 		 Ignoring unknown pragmas in system header file unless          
- 		 an explcit -Wunknown-pragmas has been given. */                
- 	      if (warn_unknown_pragmas > 1
- 		  || (warn_unknown_pragmas && ! in_system_header))
- 		warning ("ignoring pragma: %s", string);
  	    }
- 	}
        else
  	type = state = ps_done;
        break;
  
      case ps_weak:
        if (token && TREE_CODE (token) == IDENTIFIER_NODE)
  	{
--- 88,105 ----
  	{
  	  if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0)
  	    type = state = ps_pack;
+ #ifdef HANDLE_PRAGMA_WEAK
  	  else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
  	    type = state = ps_weak;
+ #endif	  
  	  else
  	    type = state = ps_done;
  	}
        else
  	type = state = ps_done;
        break;
        
+ #ifdef HANDLE_PRAGMA_WEAK
      case ps_weak:
        if (token && TREE_CODE (token) == IDENTIFIER_NODE)
  	{
*************** handle_pragma_token (string, token)
*** 109,114 ****
--- 109,115 ----
        else
  	state = ps_bad;
        break;
+ #endif
        
      case ps_name:
        state = (strcmp (string, "=") ? ps_bad : ps_equals);
*************** handle_pragma_token (string, token)
*** 177,181 ****
--- 178,184 ----
      default:
        abort ();
      }
+ 
+   return 1;
  }
  #endif /* HANDLE_SYSV_PRAGMA */


Index: c-pragma.h
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/c-pragma.h,v
retrieving revision 1.2
diff -w -p -r1.2 c-pragma.h
*** c-pragma.h	1998/04/03 16:33:29	1.2
--- c-pragma.h	1998/08/11 00:13:02
***************
*** 1,5 ****
  /* Pragma related interfaces.
!    Copyright (C) 1995 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
--- 1,5 ----
  /* Pragma related interfaces.
!    Copyright (C) 1995, 1998 Free Software Foundation, Inc.
  
  This file is part of GNU CC.
  
*************** along with GNU CC; see the file COPYING.
*** 18,23 ****
--- 18,25 ----
  the Free Software Foundation, 59 Temple Place - Suite 330,
  Boston, MA 02111-1307, USA.  */
  
+ #ifdef HANDLE_SYSV_PRAGMA
+ 
  /* Support #pragma weak iff ASM_WEAKEN_LABEL and ASM_OUTPUT_DEF are
     defined.  */
  #if defined (ASM_WEAKEN_LABEL) && defined (ASM_OUTPUT_DEF)
*************** enum pragma_state
*** 43,46 ****
  extern void handle_pragma_weak PROTO((enum pragma_state, char *, char *));
  
  /* Handle a C style pragma */
! extern void handle_pragma_token PROTO((char *, tree));
--- 45,50 ----
  extern void handle_pragma_weak PROTO((enum pragma_state, char *, char *));
  
  /* Handle a C style pragma */
! extern int handle_pragma_token PROTO((char *, tree));
! 
! #endif /* HANDLE_SYSV_PRAGMA */

Index: varasm.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/varasm.c,v
retrieving revision 1.37
diff -w -p -r1.37 varasm.c
*** varasm.c	1998/07/06 22:40:02	1.37
--- varasm.c	1998/08/11 00:13:44
*************** output_constructor (exp, size)
*** 4242,4247 ****
--- 4242,4248 ----
      assemble_zeros (size - total_bytes);
  }
  
+ #ifdef HANDLE_PRAGMA_WEAK
  /* Output asm to handle ``#pragma weak'' */
  
  void
*************** handle_pragma_weak (what, name, value)
*** 4249,4255 ****
       enum pragma_state what;
       char *name, *value;
  {
- #ifdef HANDLE_PRAGMA_WEAK
    if (what == ps_name || what == ps_value)
      {
        struct weak_syms *weak =
--- 4250,4255 ----
*************** handle_pragma_weak (what, name, value)
*** 4271,4278 ****
      }
    else if (! (what == ps_done || what == ps_start))
      warning ("malformed `#pragma weak'");
- #endif /* HANDLE_PRAGMA_WEAK */
  }
  
  /* Declare DECL to be a weak symbol.  */
  
--- 4271,4278 ----
      }
    else if (! (what == ps_done || what == ps_start))
      warning ("malformed `#pragma weak'");
  }
+ #endif /* HANDLE_PRAGMA_WEAK */
  
  /* Declare DECL to be a weak symbol.  */
  
Index: tm.texi
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/tm.texi,v
retrieving revision 1.43
diff -w -p -r1.43 tm.texi
*** tm.texi	1998/07/13 17:20:29	1.43
--- tm.texi	1998/08/11 00:13:19
*************** Define this macro if you want to impleme
*** 7316,7322 ****
  is a C expression whose value is 1 if the pragma was handled by the function.
  The argument @var{stream} is the stdio input stream from which the source text
  can be read.  @var{node} is the tree node for the identifier after the
! @code{#pragma}.
  
  It is generally a bad idea to implement new uses of @code{#pragma}.  The
  only reason to define this macro is for compatibility with other
--- 7316,7324 ----
  is a C expression whose value is 1 if the pragma was handled by the function.
  The argument @var{stream} is the stdio input stream from which the source text
  can be read.  @var{node} is the tree node for the identifier after the
! @code{#pragma}.  If USE_CPPLIB is set, then @var{stream} will be NULL.
! If the pragma is not handled, the input stream must be left in the same
! state as it was before HANDLE_PRAGMA was called.
  
  It is generally a bad idea to implement new uses of @code{#pragma}.  The
  only reason to define this macro is for compatibility with other


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