Change HANDLE_PRAGMA macro so that it will work with USE_CPPLIB.

Add INSERT_ATTRIBUTES macro.

From-SVN: r22165
This commit is contained in:
Nick Clifton 1998-09-02 09:59:57 +00:00 committed by Nick Clifton
parent 56420c2cf3
commit f09db6e0ca
8 changed files with 164 additions and 55 deletions

View File

@ -1,3 +1,35 @@
Wed Sep 2 09: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.
(pragma_getc): New function: retrieves characters from the
input stream. Defined when HANDLE_PRAGMA is enabled.
(pragma_ungetc): New function: replaces characters back into the
input stream. Defined when HANDLE_PRAGMA is enabled.
* 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.
* c-common,c (decl_attributes): If defined call the expression
contained within the INSERT_ATTRIBUTES macro before adding
attributes to a decl.
* tm.texi (HANDLE_PRAGMA): Document the new verion of
HANDLE_PRAGMA, which takes three arguments.
(INSERT_ATTRIBUTES): Document this new macro.
* LANGUAGES: Document the new version of HANDLE_PRAGMA and the
new INSERT_ATTRIBUTES macro.
Wed Sep 2 02:03:23 1998 David S. Miller <davem@pierdol.cobaltmicro.com>
* config/sparc/sparc.md (movdf): Only generate special RTL for

View File

@ -6,6 +6,18 @@ time as we can formally start documenting the interface this file will
serve as a repository for information on these interface and any incompatable
changes we've made.
Aug 31, 1998:
The interface to HANDLE_PRAGMA has changed. It now takes three arguments.
The first two are pointers to functions that should be used to read characters
from the input stream, and to push them back into the input stream respectively.
The third argument is a pointer to a null terminate string which is the first
word after #pragma. The expression supplied by HANDLE_PRAGMA should return
non-zero if it parsed and implemented the pragma. Otherwise it should return
zero, and leave the input stream as it was before the expression was evaluated.
A new back-end definable macro has been added: INSERT_ATTRIBUTES. This macro
allows backend to add attributes to decls as they are created.
Jun 10, 1998:
The interface to lang_decode_option has changed. It now uses and argc/argv
interface to allow for options that use more than one input string. The new

View File

@ -420,6 +420,10 @@ decl_attributes (node, attributes, prefix_attributes)
else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't')
type = node, is_type = 1;
#ifdef INSERT_ATTRIBUTES
INSERT_ATTRIBUTES (node, & attributes, & prefix_attributes);
#endif
attributes = chainon (prefix_attributes, attributes);
for (a = attributes; a; a = TREE_CHAIN (a))
@ -644,7 +648,7 @@ decl_attributes (node, attributes, prefix_attributes)
= (args ? TREE_VALUE (args)
: size_int (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
int align;
/* Strip any NOPs of any kind. */
while (TREE_CODE (align_expr) == NOP_EXPR
|| TREE_CODE (align_expr) == CONVERT_EXPR

View File

@ -479,6 +479,22 @@ extend_token_buffer (p)
return token_buffer + offset;
}
#if defined HANDLE_PRAGMA
/* Local versions of these macros, that can be passed as function pointers. */
static int
pragma_getc ()
{
return GETC();
}
static void
pragma_ungetc (arg)
int arg;
{
UNGETC (arg);
}
#endif
/* At the beginning of a line, increment the line number
and process any #-directive on this line.
If the line is a #-directive, read the entire line and return a newline.
@ -530,34 +546,43 @@ check_newline ()
c = GETC ();
if (c == '\n')
return c;
#ifdef HANDLE_SYSV_PRAGMA
#if defined HANDLE_PRAGMA || defined HANDLE_SYSV_PRAGMA
UNGETC (c);
token = yylex ();
if (token != IDENTIFIER)
goto skipline;
return handle_sysv_pragma (token);
#else /* !HANDLE_SYSV_PRAGMA */
#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
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;
c = nextchar, nextchar = -1;
UNGETC (c);
}
#else
??? do not know what to do ???;
#endif /* !USE_CPPLIB */
#endif
if (HANDLE_PRAGMA (pragma_getc, pragma_ungetc,
IDENTIFIER_POINTER (yylval.ttype)))
return GETC ();
#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;
}
}
@ -842,7 +867,7 @@ handle_sysv_pragma (token)
handle_pragma_token (token_buffer, yylval.ttype);
break;
default:
handle_pragma_token (token_buffer, 0);
handle_pragma_token (token_buffer, NULL);
}
#if !USE_CPPLIB
if (nextchar >= 0)
@ -853,12 +878,11 @@ handle_sysv_pragma (token)
while (c == ' ' || c == '\t')
c = GETC ();
if (c == '\n' || c == EOF)
{
handle_pragma_token (0, 0);
return c;
}
UNGETC (c);
if (c == '\n' || c == EOF)
return handle_pragma_token (NULL, NULL);
token = yylex ();
}
}

View File

@ -1,5 +1,5 @@
/* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
Copyright (C) 1992, 1997 Free Software Foundation, Inc.
Copyright (C) 1992, 1997, 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
@ -37,13 +37,12 @@ Boston, MA 02111-1307, USA. */
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. */
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. */
void
int
handle_pragma_token (string, token)
char *string;
tree token;
@ -53,26 +52,33 @@ handle_pragma_token (string, token)
static char *value;
static int align;
if (string == 0)
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'");
{
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;
return ret_val;
}
switch (state)
@ -82,24 +88,18 @@ handle_pragma_token (string, token)
{
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;
/* 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);
}
type = state = ps_done;
}
else
type = state = ps_done;
break;
#ifdef HANDLE_PRAGMA_WEAK
case ps_weak:
if (token && TREE_CODE (token) == IDENTIFIER_NODE)
{
@ -109,7 +109,8 @@ handle_pragma_token (string, token)
else
state = ps_bad;
break;
#endif
case ps_name:
state = (strcmp (string, "=") ? ps_bad : ps_equals);
break;
@ -177,5 +178,7 @@ handle_pragma_token (string, token)
default:
abort ();
}
return 1;
}
#endif /* HANDLE_SYSV_PRAGMA */

View File

@ -1,5 +1,5 @@
/* Pragma related interfaces.
Copyright (C) 1995 Free Software Foundation, Inc.
Copyright (C) 1995, 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
@ -18,6 +18,8 @@ along with GNU CC; see the file COPYING. If not, write to
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)
@ -43,4 +45,6 @@ enum pragma_state
extern void handle_pragma_weak PROTO((enum pragma_state, char *, char *));
/* Handle a C style pragma */
extern void handle_pragma_token PROTO((char *, tree));
extern int handle_pragma_token PROTO((char *, tree));
#endif /* HANDLE_SYSV_PRAGMA */

View File

@ -7315,18 +7315,32 @@ C++, which is to pretend that the file's contents are enclosed in
@findex HANDLE_PRAGMA
@findex #pragma
@findex pragma
@item HANDLE_PRAGMA (@var{stream}, @var{node})
@item HANDLE_PRAGMA (@var{getc}, @var{ungetc}, @var{node})
Define this macro if you want to implement any pragmas. If defined, it
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}.
is a C expression whose value is 1 if the pragma was handled by the
function, zero otherwise. The argument @var{getc} is a function of type
@samp{int (*)(void)} which will return the next character in the input
stream, or EOF if no characters are left. The argument @var{ungetc} is
a function of type @samp{void (*)(int)} which will push a character back
into the input stream. The argument @var{name} is the word following
#pragma in the input stream. The input stream pointer will be pointing
just beyond the end of this word. The input stream should be left
undistrubed if the expression returns zero, otherwise it should be
pointing at the last character after the end of the pragma (newline or
end-of-file).
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
compilers that do support @code{#pragma} for the sake of any user
programs which already use it.
If the pragma can be implemented by atttributes then the macro
@samp{INSERT_ATTRIBUTES} might be a useful one to define as well.
Note: older versions of this macro only had two arguments: @var{stream}
and @var{token}. The macro was changed in order to allow it to work
when gcc is built both with and without a cpp library.
@findex VALID_MACHINE_DECL_ATTRIBUTE
@item VALID_MACHINE_DECL_ATTRIBUTE (@var{decl}, @var{attributes}, @var{identifier}, @var{args})
If defined, a C expression whose value is nonzero if @var{identifier} with
@ -7367,11 +7381,27 @@ of @var{olddecl}. Examples of when this is needed are when one attribute
overrides another, or when an attribute is nullified by a subsequent
definition.
@findex INSERT_ATTRIBUTES
@item INSERT_ATTRIBUTES (@var{node}, @var{attr_ptr}, @var{prefix_ptr})
Define this macro if you want to be able to add attributes to a decl
when it is being created. This is normally useful for backends which
wish to implement a pragma by using the attributes which correspond to
the pragma's effect. The @var{node} argument is the decl which is being
created. The @var{attr_ptr} argument is a pointer to the attribute list
for this decl. The @var{prefix_ptr} is a pointer to the list of
attributes that have appeared after the specifiers and modifiers of the
declaration, but before the declaration proper.
@findex SET_DEFAULT_DECL_ATTRIBUTES
@item SET_DEFAULT_DECL_ATTRIBUTES (@var{decl}, @var{attributes})
If defined, a C statement that assigns default attributes to
newly defined @var{decl}.
@findex SET_DEFAULT_SECTION_NAME
@item SET_DEFAULT_SECTION_NAME (@var{decl})
If defined, a C statement that assigns a section name to the newly
created @var{decl}.
@findex DOLLARS_IN_IDENTIFIERS
@item DOLLARS_IN_IDENTIFIERS
Define this macro to control use of the character @samp{$} in identifier

View File

@ -4244,6 +4244,7 @@ output_constructor (exp, size)
assemble_zeros (size - total_bytes);
}
#ifdef HANDLE_PRAGMA_WEAK
/* Output asm to handle ``#pragma weak'' */
void
@ -4251,7 +4252,6 @@ handle_pragma_weak (what, name, value)
enum pragma_state what;
char *name, *value;
{
#ifdef HANDLE_PRAGMA_WEAK
if (what == ps_name || what == ps_value)
{
struct weak_syms *weak =
@ -4273,8 +4273,8 @@ handle_pragma_weak (what, name, value)
}
else if (! (what == ps_done || what == ps_start))
warning ("malformed `#pragma weak'");
#endif /* HANDLE_PRAGMA_WEAK */
}
#endif /* HANDLE_PRAGMA_WEAK */
/* Declare DECL to be a weak symbol. */